summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorYukihiro Matsumoto <matz@ruby-lang.org>1994-12-08 14:17:29 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-08-17 22:09:30 +0900
commit00e36aa09f54925c2f9c30524b48f4f54a9adb23 (patch)
tree57bf15576109b53406796c66b29d5e11d9fd99c0 /sample
parent4dfd93c72a9a221c5575c5888483f2fb55c82117 (diff)
version 0.60v0_60
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.60.tar.gz Thu Dec 8 14:17:29 1994 Yukihiro Matsumoto (matz@ix-02) * 0.60 released - alpha test baseline.
Diffstat (limited to 'sample')
-rw-r--r--sample/Artistic117
-rw-r--r--sample/aset.rb6
-rw-r--r--sample/attr.rb11
-rw-r--r--sample/biorhythm.rb201
-rw-r--r--sample/case.rb12
-rw-r--r--sample/cat.rb1
-rw-r--r--sample/cat2.rb1
-rw-r--r--sample/cbreak.rb2
-rw-r--r--sample/clnt.rb2
-rw-r--r--sample/clone.rb6
-rw-r--r--sample/const.rb4
-rw-r--r--sample/dbm.rb8
-rw-r--r--sample/dir.rb7
-rw-r--r--sample/evaldef.rb5
-rw-r--r--sample/export.rb5
-rw-r--r--sample/fib.rb2
-rw-r--r--sample/freq.rb4
-rw-r--r--sample/gctest.rb1
-rw-r--r--sample/hash.rb7
-rw-r--r--sample/io.rb3
-rwxr-xr-xsample/less.rb15
-rw-r--r--sample/list.rb42
-rw-r--r--sample/list2.rb2
-rw-r--r--sample/list3.rb4
-rw-r--r--sample/math.rb2
-rwxr-xr-xsample/mpart.rb2
-rw-r--r--sample/newver.rb13
-rw-r--r--sample/occur.rb2
-rw-r--r--sample/occur2.rb2
-rw-r--r--sample/opt_s.rb4
-rw-r--r--sample/opt_x.rb6
-rw-r--r--sample/perror.rb7
-rw-r--r--sample/rcs.awk33
-rw-r--r--sample/rcs.dat17
-rw-r--r--sample/rcs.rb46
-rw-r--r--sample/reach.rb5
-rw-r--r--sample/resp.rb2
-rw-r--r--sample/samp.rb3
-rw-r--r--sample/sieve.rb1
-rw-r--r--sample/split.rb1
-rw-r--r--sample/struct.rb4
-rw-r--r--sample/svr.rb3
-rw-r--r--sample/system.rb1
43 files changed, 127 insertions, 495 deletions
diff --git a/sample/Artistic b/sample/Artistic
deleted file mode 100644
index fbf7989..0000000
--- a/sample/Artistic
+++ /dev/null
@@ -1,117 +0,0 @@
-
-
-
-
- The "Artistic License"
-
- Preamble
-
-The intent of this document is to state the conditions under which a
-Package may be copied, such that the Copyright Holder maintains some
-semblance of artistic control over the development of the package,
-while giving the users of the package the right to use and distribute
-the Package in a more-or-less customary fashion, plus the right to make
-reasonable modifications.
-
-Definitions:
-
- "Package" refers to the collection of files distributed by the
- Copyright Holder, and derivatives of that collection of files
- created through textual modification.
-
- "Standard Version" refers to such a Package if it has not been
- modified, or has been modified in accordance with the wishes
- of the Copyright Holder.
-
- "Copyright Holder" is whoever is named in the copyright or
- copyrights for the package.
-
- "You" is you, if you're thinking about copying or distributing
- this Package.
-
- "Reasonable copying fee" is whatever you can justify on the
- basis of media cost, duplication charges, time of people involved,
- and so on. (You will not be required to justify it to the
- Copyright Holder, but only to the computing community at large
- as a market that must bear the fee.)
-
- "Freely Available" means that no fee is charged for the item
- itself, though there may be fees involved in handling the item.
- It also means that recipients of the item may redistribute it
- under the same conditions they received it.
-
-1. You may make and give away verbatim copies of the source form of the
-Standard Version of this Package without restriction, provided that you
-duplicate all of the original copyright notices and associated disclaimers.
-
-2. You may apply bug fixes, portability fixes and other modifications
-derived from the Public Domain or from the Copyright Holder. A Package
-modified in such a way shall still be considered the Standard Version.
-
-3. You may otherwise modify your copy of this Package in any way, provided
-that you insert a prominent notice in each changed file stating how and
-when you changed that file, and provided that you do at least ONE of the
-following:
-
- a) place your modifications in the Public Domain or otherwise make them
- Freely Available, such as by posting said modifications to Usenet or
- an equivalent medium, or placing the modifications on a major archive
- site such as uunet.uu.net, or by allowing the Copyright Holder to include
- your modifications in the Standard Version of the Package.
-
- b) use the modified Package only within your corporation or organization.
-
- c) rename any non-standard executables so the names do not conflict
- with standard executables, which must also be provided, and provide
- a separate manual page for each non-standard executable that clearly
- documents how it differs from the Standard Version.
-
- d) make other distribution arrangements with the Copyright Holder.
-
-4. You may distribute the programs of this Package in object code or
-executable form, provided that you do at least ONE of the following:
-
- a) distribute a Standard Version of the executables and library files,
- together with instructions (in the manual page or equivalent) on where
- to get the Standard Version.
-
- b) accompany the distribution with the machine-readable source of
- the Package with your modifications.
-
- c) accompany any non-standard executables with their corresponding
- Standard Version executables, giving the non-standard executables
- non-standard names, and clearly documenting the differences in manual
- pages (or equivalent), together with instructions on where to get
- the Standard Version.
-
- d) make other distribution arrangements with the Copyright Holder.
-
-5. You may charge a reasonable copying fee for any distribution of this
-Package. You may charge any fee you choose for support of this Package.
-You may not charge a fee for this Package itself. However,
-you may distribute this Package in aggregate with other (possibly
-commercial) programs as part of a larger (possibly commercial) software
-distribution provided that you do not advertise this Package as a
-product of your own.
-
-6. The scripts and library files supplied as input to or produced as
-output from the programs of this Package do not automatically fall
-under the copyright of this Package, but belong to whomever generated
-them, and may be sold commercially, and may be aggregated with this
-Package.
-
-7. C subroutines supplied by you and linked into this Package in order
-to emulate subroutines and variables of the language defined by this
-Package shall not be considered part of this Package, but are the
-equivalent of input as in Paragraph 6, provided these subroutines do
-not change the language in any way that would cause it to fail the
-regression tests for the language.
-
-8. The name of the Copyright Holder may not be used to endorse or promote
-products derived from this software without specific prior written permission.
-
-9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-
- The End
diff --git a/sample/aset.rb b/sample/aset.rb
index cfec649..414c13b 100644
--- a/sample/aset.rb
+++ b/sample/aset.rb
@@ -1,3 +1,7 @@
+# array set example
+# output:
+# 07045
+
ary = [0, 0, 4, 5]
ary[1, 0] = [7]
-print(ary, "\n")
+print ary, "\n"
diff --git a/sample/attr.rb b/sample/attr.rb
index 2db79f1..8326529 100644
--- a/sample/attr.rb
+++ b/sample/attr.rb
@@ -1,9 +1,14 @@
+# attribute access example
+# output:
+# 10
+# #<Foo: @test=10>
+
class Foo
- attr("test", %TRUE)
+ attr "test", %TRUE
end
foo = Foo.new
foo.test = 10
-print(foo.test, "\n")
+print foo.test, "\n"
foo._inspect.print
-print("\n")
+print "\n"
diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb
deleted file mode 100644
index eb14ca7..0000000
--- a/sample/biorhythm.rb
+++ /dev/null
@@ -1,201 +0,0 @@
-#!/mp/free/bin/ruby
-#
-# biorhythm.rb -
-# $Release Version: $
-# $Revision: 1.6 $
-# $Date: 1994/02/24 10:23:34 $
-# by Yasuo OHBA(STAFS Development Room)
-#
-# --
-#
-#
-#
-
-$RCS_ID="$Header: /var/ohba/RCS/biorhythm.rb,v 1.6 1994/02/24 10:23:34 ohba Exp ohba $"
-
-include Math
-load("parsearg.rb")
-
-$wochentag = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
-monatstag1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
-monatstag2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
-
-def usage()
- print("Usage:\n")
- print("biorhythm.rb [options]\n")
- print(" options...\n")
- print(" -D YYYYMMDD(birthday) : すべて default 値を使う. \n")
- print(" --sdate | --date YYYYMMDD : system date もしくは指定した日付を使う.\n")
- print(" --birthday YYYYMMDD : 誕生日の指定をする. \n")
- print(" -v | -g : Values or Graph の指定. \n")
- print(" --days DAYS : 期間の指定をする(Graph の時のみ有効). \n")
- print(" --help : help\n")
-end
-$USAGE = 'usage'
-
-def leapyear(y)
- ta = 0
- if ((y % 4.0) == 0); ta = 1; end
- if ((y % 100.0) == 0); ta = 0; end
- if ((y % 400.0) == 0); ta = 1; end
- return ta
-end
-
-def bcalc(tt, m, j)
- ta = 0
- if (m <= 2)
- ta = (m - 1) * 31
- else
- ta = leapyear(j)
- ta = ta + ((306 * m - 324) / 10.0).to_i
- end
- ta = ta + (j - 1) * 365 + ((j - 1) / 4.0).to_i
- ta = ta - ((j - 1) / 100) + ((j - 1) / 400.0).to_i
- ta = ta + tt
- return ta
-end
-
-def printHeader(tg, mg, jg, gtag, tage)
- print("\n")
- print(" Biorhythm\n")
- print(" =========\n")
- print("\n")
- printf("The birthday %04d.%02d.%02d is a %s\n", jg, mg, tg, $wochentag[gtag])
- printf("Age in days: [%d]\n", tage)
-end
-
-def getPosition(z)
- pi = 3.14159265
- $phys = (50.0 * (1.0 + sin((z / 23.0 - (z / 23)) * 360.0 * pi / 180.0))).to_i
- $emot = (50.0 * (1.0 + sin((z / 28.0 - (z / 28)) * 360.0 * pi / 180.0))).to_i
- $geist =(50.0 * (1.0 + sin((z / 33.0 - (z / 33)) * 360.0 * pi / 180.0))).to_i
-end
-
-#
-# main program
-#
-parseArgs(0, nil, "vg", "D:", "sdate", "date:", "birthday:", "days:")
-
-printf($stderr, "\n")
-printf($stderr, "Biorhythm (c) 1987-1994 V3.0\n")
-printf($stderr, "\n")
-if ($OPT_D)
- dtmp = Time.now.strftime("%Y%m%d")
- jh = dtmp[0,4].to_i
- mh = dtmp[4,2].to_i
- th = dtmp[6,2].to_i
- dtmp = $OPT_D
- jg = dtmp[0,4].to_i
- mg = dtmp[4,2].to_i
- tg = dtmp[6,2].to_i
- gtag = bcalc(tg, mg, jg) % 7
- ausgabeart = "g"
-else
- if ($OPT_birthday)
- dtmp = $OPT_birthday
- else
- printf($stderr, "Birthday (YYYYMMDD) : ")
- dtmp = $stdin.gets.chop
- end
- if (dtmp.length != 8)
- printf($stderr, "BAD Input Birthday!!\n")
- exit()
- end
- jg = dtmp[0,4].to_i
- mg = dtmp[4,2].to_i
- tg = dtmp[6,2].to_i
-
- gtag = bcalc(tg, mg, jg) % 7
-
- if ($OPT_sdate)
- dtmp = Time.now.strftime("%Y%m%d")
- elsif ($OPT_date)
- dtmp = $OPT_date
- else
- printf($stderr, "Date [<RETURN> for Systemdate] (YYYYMMDD) : ")
- dtmp = $stdin.gets.chop
- end
- if (dtmp.length != 8)
- dtmp = Time.now.strftime("%Y%m%d")
- end
- jh = dtmp[0,4].to_i
- mh = dtmp[4,2].to_i
- th = dtmp[6,2].to_i
-
- if ($OPT_v)
- ausgabeart = "v"
- elsif ($OPT_g)
- ausgabeart = "g"
- else
- printf($stderr, "Values for today or Graph (v/g) [default g] : ")
- ausgabeart = $stdin.gets.chop
- end
-end
-if (ausgabeart == "v")
- tag = bcalc(tg, mg, jg)
- tah = bcalc(th, mh, jh)
- tage = tah - tag
- printHeader(tg, mg, jg, gtag, tage)
- print("\n")
-
- getPosition(tage)
- printf("Biorhythm: %04d.%02d.%02d\n", jh, mh, th)
- printf("Physical: %d%%\n", $phys)
- printf("Emotional: %d%%\n", $emot)
- printf("Mental: %d%%\n", $geist)
- print("\n")
-else
- if ($OPT_days)
- ktage = $OPT_days.to_i
- else
- if ($OPT_D)
- ktage = 9
- else
- printf($stderr, "Graph for how many days [default 10] : ")
- ktage = $stdin.gets.chop
- if (ktage == "")
- ktage = 9
- else
- ktage = ktage.to_i - 1
- end
- end
- end
- tag = bcalc(tg, mg, jg)
- tah = bcalc(th, mh, jh)
- tage = tah - tag
- printHeader(tg, mg, jg, gtag, tage)
- print(" P=physical, E=emotional, M=mental\n")
- print(" -------------------------+-------------------------\n")
- print(" Bad Condition | Good Condition\n")
- print(" -------------------------+-------------------------\n")
-
- for z in tage..(tage + ktage)
- getPosition(z)
-
- printf("%04d.%02d.%02d : ", jh, mh, th)
- p = ($phys / 2.0 + 0.5).to_i
- e = ($emot / 2.0 + 0.5).to_i
- g = ($geist / 2.0 + 0.5).to_i
- graph = "." * 51
- graph[25] = ?|
- graph[p] = ?P
- graph[e] = ?E
- graph[g] = ?M
- print(graph, "\n")
- th = th + 1
- if (leapyear(jh) == 0)
- $MONATSTAG = monatstag1
- else
- $MONATSTAG = monatstag2
- end
- if (th > $MONATSTAG[mh - 1])
- mh = mh + 1
- th = 1
- end
- if (mh > 12)
- jh = jh + 1
- mh = 1
- end
- end
- print(" -------------------------+-------------------------\n\n")
-end
diff --git a/sample/case.rb b/sample/case.rb
index f456f02..e844cdd 100644
--- a/sample/case.rb
+++ b/sample/case.rb
@@ -1,12 +1,14 @@
+# case statement example
+# output:
+# 3..5
case "t"
when /1/
- print(1, "\n")
+ print 1, "\n"
when /t/
- print(3..5, "\n")
+ print 3..5, "\n"
when /./
- print(2, "\n")
+ print 2, "\n"
else
- print("else\n")
+ print "else\n"
end
-
diff --git a/sample/cat.rb b/sample/cat.rb
index 93f0289..a3243d3 100644
--- a/sample/cat.rb
+++ b/sample/cat.rb
@@ -1,3 +1,4 @@
+# cat -n & `...' operator test
while gets()
if $. == 1 ... ~ /^\*/; print("--") end
printf("%5d: %s", $., $_)
diff --git a/sample/cat2.rb b/sample/cat2.rb
index f979dc5..bbc1ebb 100644
--- a/sample/cat2.rb
+++ b/sample/cat2.rb
@@ -1,3 +1,4 @@
+# cat -n & `...' operator test
while gets()
if 1 ... /^\*/; print("--") end
printf("%5d: %s", $., $_)
diff --git a/sample/cbreak.rb b/sample/cbreak.rb
index 5befd50..6d3d551 100644
--- a/sample/cbreak.rb
+++ b/sample/cbreak.rb
@@ -1,3 +1,5 @@
+# ioctl example works on Sun
+
%CBREAK = 0x00000002
%ECHO = 0x00000008
%TIOCGETP = 0x40067408
diff --git a/sample/clnt.rb b/sample/clnt.rb
index 639e2a0..a687d12 100644
--- a/sample/clnt.rb
+++ b/sample/clnt.rb
@@ -1,3 +1,5 @@
+# socket example - client side
+# usage: ruby clnt.rb [host] port
host=(if $ARGV.length == 2; $ARGV.shift; else "localhost"; end)
print("Trying ", host, " ...")
$stdout.flush
diff --git a/sample/clone.rb b/sample/clone.rb
index 6a752e8..69d2f1d 100644
--- a/sample/clone.rb
+++ b/sample/clone.rb
@@ -1,3 +1,9 @@
+# object cloning & single method test
+# output:
+# test2
+# test
+# test
+# clone.rb:13: undefined method `test2' for "#<Object: 0xbfca4>"(Object)
foo = Object.new
def foo.test
print("test\n")
diff --git a/sample/const.rb b/sample/const.rb
index d7629fe..783965c 100644
--- a/sample/const.rb
+++ b/sample/const.rb
@@ -1,3 +1,7 @@
+# constant access test
+# output:
+# 1234
+# 1268
%test1 = 1
%test2 = 2
diff --git a/sample/dbm.rb b/sample/dbm.rb
index 128391f..cdec665 100644
--- a/sample/dbm.rb
+++ b/sample/dbm.rb
@@ -1,6 +1,4 @@
-# ruby
-#
-
+# ruby dbm acess
d = DBM.open("test")
-for k in d.keys; print(k, "\n"); end
-for v in d.values; print(v, "\n"); end
+for k in d.keys; print k, "\n"; end
+for v in d.values; print v, "\n"; end
diff --git a/sample/dir.rb b/sample/dir.rb
index f4c3d17..f269c56 100644
--- a/sample/dir.rb
+++ b/sample/dir.rb
@@ -1,9 +1,10 @@
+# directory access
+# list all files but .*/*~/*.o
dirp = Dir.open(".")
dirp.rewind
for f in dirp
- if (~/^\./ || ~/~$/ || ~/\.o/)
- else
- print(f, "\n")
+ unless (~/^\./ || ~/~$/ || ~/\.o/)
+ print f, "\n"
end
end
dirp.close
diff --git a/sample/evaldef.rb b/sample/evaldef.rb
index c261b53..021f658 100644
--- a/sample/evaldef.rb
+++ b/sample/evaldef.rb
@@ -1,3 +1,8 @@
+# method definition by eval()
+# output:
+# bar
+# (eval):21: method `baz' not available for "#<foo: 0xbfc5c>"(foo)
+
class foo
def foo
eval("
diff --git a/sample/export.rb b/sample/export.rb
index 3a6a819..ea6c5ae 100644
--- a/sample/export.rb
+++ b/sample/export.rb
@@ -1,3 +1,8 @@
+# methos access permission
+# output:
+# foobar
+# foo
+
class foo
export(\printf)
end
diff --git a/sample/fib.rb b/sample/fib.rb
index 9fb8b24..cde4fba 100644
--- a/sample/fib.rb
+++ b/sample/fib.rb
@@ -1,3 +1,5 @@
+# calculate Fibonacci(20)
+# for benchmark
def fib(n)
if n<2
n
diff --git a/sample/freq.rb b/sample/freq.rb
index 7417e0b..0c433ae 100644
--- a/sample/freq.rb
+++ b/sample/freq.rb
@@ -1,5 +1,5 @@
-#
-
+# word occurrence listing
+# usege: ruby freq.rb file..
freq = {}
while gets()
while sub(/\w+/, '')
diff --git a/sample/gctest.rb b/sample/gctest.rb
index 23476d2..6810b95 100644
--- a/sample/gctest.rb
+++ b/sample/gctest.rb
@@ -1,3 +1,4 @@
+# GC stress test
def cons(car, cdr)
[car, cdr]
end
diff --git a/sample/hash.rb b/sample/hash.rb
index 126b17d..85f719e 100644
--- a/sample/hash.rb
+++ b/sample/hash.rb
@@ -1,3 +1,10 @@
+# hash value
+# output:
+# 78651
+# 78651
+# 78651
+# -45637
+
print(+-1.0.hash,"\n")
print(-1.0.hash,"\n")
print((-1.0).hash,"\n")
diff --git a/sample/io.rb b/sample/io.rb
index 0b8a537..c3c1a47 100644
--- a/sample/io.rb
+++ b/sample/io.rb
@@ -1,3 +1,6 @@
+# IO test
+# usage: ruby io.rb file..
+
home = getenv("HOME")
home.sub("m", "&&")
print(home, "\n")
diff --git a/sample/less.rb b/sample/less.rb
index e818e7a..6960b9c 100755
--- a/sample/less.rb
+++ b/sample/less.rb
@@ -1,17 +1,4 @@
-#! /mp/free/bin/ruby -- -*- ruby -*-
-#
-# less -
-# $Release Version: $
-# $Revision: 1.1 $
-# $Date: 90/09/29 15:17:59 $
-# by Yasuo OHBA(STAFS Development Room)
-#
-# --
-#
-#
-#
-
-$RCS_ID="$Header: less,v 1.1 90/09/29 15:17:59 ohba Locked $"
+#! /usr/local/bin/ruby -- -*- ruby -*-
ZCAT = "/usr/local/bin/zcat"
LESS = "/usr/local/bin/less"
diff --git a/sample/list.rb b/sample/list.rb
index e0b5b38..1a20c95 100644
--- a/sample/list.rb
+++ b/sample/list.rb
@@ -1,10 +1,16 @@
-# Linked list program
+# Linked list example
class MyElem
+ #クラスメソッド(相当)の定義
def MyElem.new(item)
- super.init(item)
+ # スーパークラスのメソッドの呼び出し(この場合はクラスClass)
+ elm = super # 変数宣言は要らない
+ #elmに対するメソッドの呼び出し
+ elm.init(item)
end
-
+
+ # 通常のメソッド定義
def init(item)
+ # @変数はインスタンス変数(宣言は要らない)
@data = item
@next = nil
self
@@ -18,6 +24,7 @@ class MyElem
@next
end
+ # 「obj.data = val」としたときに暗黙に呼ばれるメソッド
def next=(new)
@next = new
end
@@ -42,9 +49,12 @@ class MyList
end
end
+ # オブジェクトを文字列に変換するメソッド
+ # これを再定義するとprintでの表現が変わる
def to_s
str = "<MyList:\n";
for elt in self
+ # 「str = str + elt.data.to_s + "\n"」の省略形
str += elt.data.to_s + "\n"
end
str += ">"
@@ -66,16 +76,18 @@ class Point
sprintf("%d@%d", @x, @y)
end
end
-
-list1 = MyList.new
-list1.add_to_list(10)
-list1.add_to_list(20)
-list1.add_to_list(Point.new(2, 3))
-list1.add_to_list(Point.new(4, 5))
-list2 = MyList.new
-list2.add_to_list(20)
-list2.add_to_list(Point.new(4, 5))
-list2.add_to_list(list1)
-print("list1:\n", list1, "\n")
-print("list2:\n", list2, "\n")
+# 大域変数は`$'で始まる.
+$list1 = MyList.new
+$list1.add_to_list(10)
+$list1.add_to_list(20)
+$list1.add_to_list(Point.new(2, 3))
+$list1.add_to_list(Point.new(4, 5))
+$list2 = MyList.new
+$list2.add_to_list(20)
+$list2.add_to_list(Point.new(4, 5))
+$list2.add_to_list($list1)
+
+# 曖昧でない限りメソッド呼び出しの括弧は省略できる
+print "list1:\n", $list1, "\n"
+print "list2:\n", $list2, "\n"
diff --git a/sample/list2.rb b/sample/list2.rb
index c2e9bca..fef9d35 100644
--- a/sample/list2.rb
+++ b/sample/list2.rb
@@ -1,4 +1,4 @@
-# Linked list program -- short version
+# Linked list example -- short version
class Point
def Point.new(x, y)
super.init(x, y)
diff --git a/sample/list3.rb b/sample/list3.rb
index c38e5bf..c627857 100644
--- a/sample/list3.rb
+++ b/sample/list3.rb
@@ -1,4 +1,6 @@
-# Linked list program -- short version
+# Linked list example -- short version
+# using _inspect
+
class Point
def Point.new(x, y)
super.init(x, y)
diff --git a/sample/math.rb b/sample/math.rb
index 83be1b9..c0b5225 100644
--- a/sample/math.rb
+++ b/sample/math.rb
@@ -1,4 +1,4 @@
-#load("lib/math.o")
+# math example
include Math
sqrt(4)
print(Math.sqrt(257), "\n")
diff --git a/sample/mpart.rb b/sample/mpart.rb
index c0f705e..2374ae0 100755
--- a/sample/mpart.rb
+++ b/sample/mpart.rb
@@ -1,4 +1,6 @@
#! ./ruby
+# split into multi part
+# usage: mpart.rb [-nnn] file..
lines = 1000
diff --git a/sample/newver.rb b/sample/newver.rb
deleted file mode 100644
index bbf03ae..0000000
--- a/sample/newver.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-#! /usr/local/bin/ruby
-
-f = open("version.h", "r")
-f.gets()
-f.close
-
-if $_ =~ /"(\d)\.(\d+)"/;
- f = open("version.h", "w")
- i = $2.to_i + 1
- printf("ruby version %d.%0d\n", $1, i)
- printf(f, "#define RUBY_VERSION \"%d.%0d\"\n", $1, i)
- f.close
-end
diff --git a/sample/occur.rb b/sample/occur.rb
index 12e469d..2141fad 100644
--- a/sample/occur.rb
+++ b/sample/occur.rb
@@ -1,3 +1,5 @@
+# word occurrence listing
+# usege: ruby occur.rb file..
freq = {}
while gets()
for word in $_.split(/\W+/)
diff --git a/sample/occur2.rb b/sample/occur2.rb
index 6e05137..899294e 100644
--- a/sample/occur2.rb
+++ b/sample/occur2.rb
@@ -1,3 +1,5 @@
+# word occurrence listing
+# usege: ruby occur2.rb file..
freq = {}
while gets()
for word in $_.split(/\W+/)
diff --git a/sample/opt_s.rb b/sample/opt_s.rb
index 5402be7..56ff0ee 100644
--- a/sample/opt_s.rb
+++ b/sample/opt_s.rb
@@ -1,4 +1,6 @@
-#! ruby -s
+#! ./ruby -s
+# test for option `-s'
+
if ($xyz)
print("xyz = TRUE\n")
end
diff --git a/sample/opt_x.rb b/sample/opt_x.rb
index 4fc9a25..47a67f6 100644
--- a/sample/opt_x.rb
+++ b/sample/opt_x.rb
@@ -1,7 +1,9 @@
+test for option `-x'
+
this is a forwarding header
this is a header too.
- #! ruby
-this is a trailing
+
+from here script starts
#! ./ruby -v
print("tt\n")
__END__
diff --git a/sample/perror.rb b/sample/perror.rb
deleted file mode 100644
index 9196525..0000000
--- a/sample/perror.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-if File._s("io.rb")
- print(File._z("io.rb", "io.rb\n")
-# print(File._s("io.rb"), ": io.rb\n")
-end
-
-for i in 1..5
-end
diff --git a/sample/rcs.awk b/sample/rcs.awk
deleted file mode 100644
index 0897928..0000000
--- a/sample/rcs.awk
+++ /dev/null
@@ -1,33 +0,0 @@
-BEGIN {
- sw = 40.0;
- dw = 78.0;
- hdw = dw / 2.0;
- w = 20.0;
- h =1.0;
- d = 0.2;
- ss="abcdefghijklmnopqrstuvwxyz0123456789!#$%^&*()-=\\[];'`,./";
- rnd = srand();
-}
-
-{
- xr = -hdw; y = h * 1.0; maxxl = -999;
- s = "";
- while (xr < hdw) {
- x = xr * (1 + y) - y * w / 2;
- i = (x / (1 + h) + sw /2);
- c = (0 < i && i < length($0)) ? substr($0, i, 1) : "0";
- y = h - d * c;
- xl = xr - w * y / (1 + y);
- if (xl < -hdw || xl >= hdw || xl <= maxxl) {
- t = rand() * length(ss);
- c = substr(ss, t, 1);
- }
- else {
- c = substr(s, xl + hdw, 1);
- maxxl = xl;
- }
- s = s c;
- xr = xr + 1;
- }
- print s;
-}
diff --git a/sample/rcs.dat b/sample/rcs.dat
deleted file mode 100644
index 61c88bf..0000000
--- a/sample/rcs.dat
+++ /dev/null
@@ -1,17 +0,0 @@
-0000000000000000220000000000000000
-0000000000000111221110000000000000
-0000000000111112222111110000000000
-0000000111111112222111111110000000
-0000111111111122222211111111110000
-0111111111111222222221111111111110
-2222222222222222222222222222222222
-1122222222222222222222222222222211
-0111122222222222222222222222211110
-0011111122222222222222222211111100
-0001111111222222222222221111111000
-0000111112222222222222222111110000
-0000011122222222112222222211100000
-0000001122222221111222222211000000
-0000000122221111111111222210000000
-0000000221111111111111111220000000
-0000000000000000000000000000000000
diff --git a/sample/rcs.rb b/sample/rcs.rb
deleted file mode 100644
index 0ed4a36..0000000
--- a/sample/rcs.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-sw = 40.0 # p^[
-dw = 78.0 # Random Character Streogram
-hdw = dw / 2.0
-w = 20.0 #
-h =1.0 #
-d = 0.2 # P
-ss="abcdefghijklmnopqrstuvwxyz0123456789!#$%^&*()-=\\[];'`,./"
-rnd = srand()
-
-while gets()
-# print($_)
- xr = -hdw; y = h * 1.0; maxxl = -999
- s = "";
- while xr < hdw
- x = xr * (1 + y) - y * w / 2
- i = (x / (1 + h) + sw /2)
- if (1 < i && i < $_.length);
- c = $_[i, 1].to_i
- else
- c = 0
- end
- y = h - d * c
- xl = xr - w * y / (1 + y);
- if xl < -hdw || xl >= hdw || xl <= maxxl
- tt = rand(ss.length)
- c = ss[tt, 1]
- else
- c = s[xl + hdw, 1]
- maxxl = xl
- end
- s = s + c
- xr = xr + 1
- end
- print(s, "\n")
-end
-
-
-
-
-
-
-
-
-
-
-
diff --git a/sample/reach.rb b/sample/reach.rb
deleted file mode 100644
index 25b3408..0000000
--- a/sample/reach.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-for i in 1..10
- print("test\n")
- break
- print("test2\n")
-end
diff --git a/sample/resp.rb b/sample/resp.rb
deleted file mode 100644
index 84516b4..0000000
--- a/sample/resp.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-undef kill
-print(responds_to("kill"), "\n")
diff --git a/sample/samp.rb b/sample/samp.rb
index b4d818f..4052a30 100644
--- a/sample/samp.rb
+++ b/sample/samp.rb
@@ -1,3 +1,6 @@
+# SpXNvg
+# g: samp.rb file..
+
P = 0
while gets()
printf("%3d: %s", $., $_)
diff --git a/sample/sieve.rb b/sample/sieve.rb
index 0228243..192a586 100644
--- a/sample/sieve.rb
+++ b/sample/sieve.rb
@@ -1,3 +1,4 @@
+# sieve of Eratosthenes
sieve = []
unless max = $ARGV.shift; max = 100; end
max = max.to_i
diff --git a/sample/split.rb b/sample/split.rb
index 73717363..2b6f392 100644
--- a/sample/split.rb
+++ b/sample/split.rb
@@ -1,3 +1,4 @@
+# split test
print("1 byte string", "\n")
print("1 byte string".reverse, "\n")
diff --git a/sample/struct.rb b/sample/struct.rb
index 7c0690b..322764d 100644
--- a/sample/struct.rb
+++ b/sample/struct.rb
@@ -1,3 +1,7 @@
+#output:
+# struct test
+# 1
+
foo = Struct.new("test", "a1"::1, "a2"::2)
print(foo, "\n")
bar = foo.clone
diff --git a/sample/svr.rb b/sample/svr.rb
index c00a03c..1c0104c 100644
--- a/sample/svr.rb
+++ b/sample/svr.rb
@@ -1,3 +1,6 @@
+# socket example - server side
+# usage: ruby svr.rb
+
gs = TCPserver.open(0)
printf("server port is on %d\n", gs.port)
socks = [gs]
diff --git a/sample/system.rb b/sample/system.rb
index 1693d90..02f3782 100644
--- a/sample/system.rb
+++ b/sample/system.rb
@@ -1 +1,2 @@
+# command string
print(`echo foobar`)