summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorYukihiro Matsumoto <matz@ruby-lang.org>1994-10-14 06:19:03 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-08-17 22:09:30 +0900
commit29f237a8b1df650089b54447f070726c75706b6f (patch)
treee6ee836a39a5f2f1d433d6532de32471b655fb6d /sample
parent173976c97c9426aa8d96e53aef6c0e570c5fdfda (diff)
version 0.54v0_54
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-0.54.tar.gz
Diffstat (limited to 'sample')
-rw-r--r--sample/caller.rb15
-rw-r--r--sample/dbm.rb2
-rw-r--r--sample/export.rb13
-rw-r--r--sample/fib.rb2
-rw-r--r--sample/fib.scm6
-rw-r--r--sample/list3.rb20
-rw-r--r--sample/ruby-mode.el5
-rwxr-xr-xsample/time.rb8
-rwxr-xr-xsample/uumerge.rb27
9 files changed, 80 insertions, 18 deletions
diff --git a/sample/caller.rb b/sample/caller.rb
deleted file mode 100644
index 8988733..0000000
--- a/sample/caller.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-def test
- for i in 1..2
- for j in 1..5
- print(j, ": ", caller(j).join(':'), "\n")
- end
- end
-end
-
-def test2
- print(1, ": ", caller(1).join(':'), "\n")
- test()
-end
-
-test2()
-caller()
diff --git a/sample/dbm.rb b/sample/dbm.rb
index 1f2886e..128391f 100644
--- a/sample/dbm.rb
+++ b/sample/dbm.rb
@@ -1,6 +1,6 @@
# ruby
#
-d = Dbm.open("test")
+d = DBM.open("test")
for k in d.keys; print(k, "\n"); end
for v in d.values; print(v, "\n"); end
diff --git a/sample/export.rb b/sample/export.rb
new file mode 100644
index 0000000..3a6a819
--- /dev/null
+++ b/sample/export.rb
@@ -0,0 +1,13 @@
+class foo
+ export(\printf)
+end
+
+def foobar
+ print "foobar\n"
+end
+
+f = foo.new
+#foo.unexport(\printf)
+foo.export(\foobar)
+f.foobar
+f.printf "%s\n", foo
diff --git a/sample/fib.rb b/sample/fib.rb
index c72f91f..9fb8b24 100644
--- a/sample/fib.rb
+++ b/sample/fib.rb
@@ -1,4 +1,4 @@
-def fib (n)
+def fib(n)
if n<2
n
else
diff --git a/sample/fib.scm b/sample/fib.scm
new file mode 100644
index 0000000..8eba75b
--- /dev/null
+++ b/sample/fib.scm
@@ -0,0 +1,6 @@
+(define (fib n)
+ (if (< n 2)
+ n
+ (+ (fib (- n 2)) (fib (- n 1)))))
+
+(fib 20)
diff --git a/sample/list3.rb b/sample/list3.rb
new file mode 100644
index 0000000..c38e5bf
--- /dev/null
+++ b/sample/list3.rb
@@ -0,0 +1,20 @@
+# Linked list program -- short version
+class Point
+ def Point.new(x, y)
+ super.init(x, y)
+ end
+
+ def init(x, y)
+ @x = x; @y = y
+ self
+ end
+
+ def to_s
+ sprintf("%d@%d", @x, @y)
+ end
+end
+
+list1 = [10, 20, Point.new(2, 3), Point.new(4, 5)]
+list2 = [20, Point.new(4, 5), list1]
+print("list1: ", list1._inspect, "\n")
+print("list2: ", list2._inspect, "\n")
diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el
index 8f864d3..7f97e71 100644
--- a/sample/ruby-mode.el
+++ b/sample/ruby-mode.el
@@ -18,7 +18,7 @@
(defconst ruby-block-end-re "end")
(defconst ruby-delimiter
- (concat "[/<(){}#\"'`]\\|\\[\\|\\]\\|\\b\\("
+ (concat "[$/<(){}#\"'`]\\|\\[\\|\\]\\|\\b\\("
ruby-block-beg-re "\\|" ruby-block-end-re "\\)\\b")
)
@@ -55,6 +55,7 @@
;;(modify-syntax-entry ?\n ">" ruby-mode-syntax-table)
;;(modify-syntax-entry ?\f ">" ruby-mode-syntax-table)
(modify-syntax-entry ?# "<" ruby-mode-syntax-table)
+ (modify-syntax-entry ?$ "/" ruby-mode-syntax-table)
(modify-syntax-entry ?\\ "'" ruby-mode-syntax-table)
(modify-syntax-entry ?_ "w" ruby-mode-syntax-table)
(modify-syntax-entry ?< "." ruby-mode-syntax-table)
@@ -193,6 +194,8 @@ The variable ruby-indent-level controls the amount of indentation.
nil
(goto-char indent-point)
(setq in-string t))))))
+ ((string= "$" w) ;skip $char
+ (forward-char 1))
((string= "#" w) ;skip comment
(forward-line 1))
((string= "(" w) ;skip to matching paren
diff --git a/sample/time.rb b/sample/time.rb
new file mode 100755
index 0000000..b0ef065
--- /dev/null
+++ b/sample/time.rb
@@ -0,0 +1,8 @@
+#! /usr/local/bin/ruby
+cmd = $ARGV.join(" ")
+b = Time.now
+system(cmd)
+e = Time.now
+ut, st, cut, cst = Time.times
+total = (e - b).to_f
+printf $stderr, "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst
diff --git a/sample/uumerge.rb b/sample/uumerge.rb
new file mode 100755
index 0000000..420a392
--- /dev/null
+++ b/sample/uumerge.rb
@@ -0,0 +1,27 @@
+#!/usr/local/bin/ruby
+
+while gets()
+ if /^begin\s*(\d*)\s*(\S*)/
+ $mode, $file = $1, $2
+ $sawbegin+=1
+ break
+ end
+end
+
+fail "missing begin" unless $sawbegin;
+OUT = open($file, "w") if $file != "";
+
+while gets()
+ if /^end/
+ $sawend+=1
+ break
+ end
+ sub(/[a-z]+$/, ""); # handle stupid trailing lowercase letters
+ continue if /[a-z]/
+ continue unless ((($_[0] - 32) & 077) + 2) / 3 == $_.length / 4
+ OUT << $_.unpack("u");
+end
+
+fail "missing end" unless $sawend;
+File.chmod $mode.oct, $file;
+exit 0;