summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
Diffstat (limited to 'sample')
-rw-r--r--sample/README60
-rw-r--r--sample/mkproto.rb8
-rw-r--r--sample/ruby-mode.el13
-rw-r--r--sample/test.rb63
-rw-r--r--sample/tsvr.rb2
5 files changed, 132 insertions, 14 deletions
diff --git a/sample/README b/sample/README
new file mode 100644
index 0000000000..90ac0c7220
--- /dev/null
+++ b/sample/README
@@ -0,0 +1,60 @@
+README this file
+biorhythm.rb biorhythm calculator
+cal.rb cal(1) clone
+cbreak.rb no echo done by ioctl
+clnt.rb socket client
+dbmtest.rb test for dbm
+dir.rb directory access
+dstore.rb object database on dbm
+eval.rb simple evaluator
+export.rb method access example
+exyacc.rb extrace BNF from yacc file
+fact.rb factorial calculator
+fib.awk Fibonacci number (AWK)
+fib.pl Fibonacci number (Perl)
+fib.py Fibonacci number (Python)
+fib.rb Fibonacci number (Ruby)
+fib.scm Fibonacci number (Scheme)
+freq.rb count word occurrence
+from.rb scan mail spool
+fullpath.rb convert ls -lR to fullpath format
+getopts.test test fot getopt.rb
+goodfriday.rb print various christian calendar event.
+inf-ruby.el program to run ruby under emacs
+io.rb io test
+less.rb front end for less
+list.rb stupid object sample
+list2.rb stupid object sample
+list3.rb stupid object sample
+mine.rb simple mine sweeper
+mkproto.rb extract protptype from C
+mpart.rb split file int multi part
+mrshtest.rb test marshal
+observ.rb observer design pattern sample
+occur.pl count word occurrence (Perl)
+occur.rb count word occurrence (Ruby)
+occur2.rb count word occurrence - another style
+philos.rb famous dining philosophers
+pi.rb calculate PI
+rbc.rb interactive ruby, to be removed by irb
+rcs.awk random character stereogram (AWK)
+rcs.rb random character stereogram (Ruby)
+rcs.dat data for random character stereogram
+regx.rb regular expression tester
+ruby-mode.el ruby mode for emacs
+rubydb2x.el ruby debugger support for emacs 19.2x or before
+rubydb3x.el ruby debugger support for emacs 19.3x or later
+sieve.rb sieve of Eratosthenes
+svr.rb socket server
+test.rb test suite used by `make test'
+time.rb /usr/bin/time clone
+tkbiff.rb mail notifier using Tk
+tkbrowse.rb directory browser using Tk
+tkdialog.rb dialog example
+tkfrom.rb scan mail spool using Tk
+tkhello.rb simple Tk example
+tkline.rb simple Tk example
+tktimer.rb stopwatch
+trojan.rb simple tool to find file that may be trojan horse.
+tsvr.rb socket server using thread
+uumerge.rb merge files and uudecode them
diff --git a/sample/mkproto.rb b/sample/mkproto.rb
index 97006f9f54..8661240085 100644
--- a/sample/mkproto.rb
+++ b/sample/mkproto.rb
@@ -8,17 +8,17 @@ while gets()
arg.gsub! ' +', ' '
if arg =~ /,/
if arg =~ /(([^*]+) *\** *[\w\d_]+),/
- type = $2.strip!
- args.push $1.strip!
+ type = $2.strip
+ args.push $1.strip
arg = $'
else
type = ""
end
while arg.sub!(/(\** *[\w\d_]+)(,|$)/, "")
- args.push type + " " + $1.strip!
+ args.push type + " " + $1.strip
end
else
- args.push arg.strip!
+ args.push arg.strip
end
end
printf "%s);\n", args.join(', ')
diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el
index d379a633c3..8bf843c1ea 100644
--- a/sample/ruby-mode.el
+++ b/sample/ruby-mode.el
@@ -209,7 +209,7 @@ The variable ruby-indent-level controls the amount of indentation.
(looking-at ruby-block-mid-re))
(progn
(goto-char (match-end 0))
- (looking-at "[^_]")))))))))
+ (looking-at "\\>")))))))))
(defun ruby-parse-region (start end)
(let ((indent-point end)
@@ -253,7 +253,7 @@ The variable ruby-indent-level controls the amount of indentation.
((looking-at "%")
(cond
((and (not (eobp)) (ruby-expr-beg)
- (looking-at "%[Qqrx]?\\(.\\)"))
+ (looking-at "%[Qqrxw]?\\(.\\)"))
(setq w (buffer-substring (match-beginning 1)
(match-end 1)))
(cond
@@ -598,7 +598,7 @@ An end of a defun is found by moving forward from the beginning of one."
("[^$\\?]\\('[^\\']*\\(\\\\\\(.\\|\n\\)[^\\']*\\)*'\\)" 1 string)
("[^$\\?]\\(`[^\\`]*\\(\\\\\\(.\\|\n\\)[^\\`]*\\)*`\\)" 1 string)
("^\\s *#.*$" nil comment)
- ("[^$@?\\]\\(#[^$@{].*$\\)" 1 comment)
+ ("[^$@?\\]\\(#[^$@{\n].*$\\)" 1 comment)
("[^a-zA-Z_]\\(\\?\\(\\\\[CM]-\\)*.\\)" 1 string)
("^\\s *\\(require\\|load\\).*$" nil include)
("^\\s *\\(include\\|alias\\|undef\\).*$" nil decl)
@@ -624,6 +624,7 @@ An end of a defun is found by moving forward from the beginning of one."
"break"
"case"
"class"
+ "def"
"do"
"elsif"
"else"
@@ -652,7 +653,7 @@ An end of a defun is found by moving forward from the beginning of one."
"while"
)
"\\|")
- "\\)[ \n\t()]")
+ "\\)\\b")
2)
;; variables
'("\\(^\\|[^_]\\)\\b\\(nil\\|self\\|true\\|false\\)\\b\\([^_]\\|$\\)"
@@ -664,8 +665,8 @@ An end of a defun is found by moving forward from the beginning of one."
'("\\(^\\|[^_]\\)\\b\\([A-Z]+[a-zA-Z0-9_]*\\)"
2 font-lock-type-face)
;; functions
- '("^\\s *def[ \t]+[^ \t(]*"
- 0 font-lock-function-name-face t))
+ '("^\\s *def[ \t]+\\([^ \t(]*\\)"
+ 1 font-lock-function-name-face t))
"*Additional expressions to highlight in ruby mode.")
(if (and (>= (string-to-int emacs-version) 19)
(not (featurep 'xemacs)))
diff --git a/sample/test.rb b/sample/test.rb
index 0adcb22307..8748b60b50 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -484,6 +484,63 @@ end
$x = [[1,2],[3,4],[5,6]]
ok($x.iter_test1{|x|x} == $x.iter_test2{|x|x})
+class IterTest
+ def initialize(e); @body = e; end
+
+ def each0(&block); @body.each(&block); end
+ def each1(&block); @body.each { |*x| block.call(*x) } end
+ def each2(&block); @body.each { |*x| block.call(x) } end
+ def each3(&block); @body.each { |x| block.call(*x) } end
+ def each4(&block); @body.each { |x| block.call(x) } end
+ def each5; @body.each { |*x| yield(*x) } end
+ def each6; @body.each { |*x| yield(x) } end
+ def each7; @body.each { |x| yield(*x) } end
+ def each8; @body.each { |x| yield(x) } end
+end
+
+IterTest.new([0]).each0 { |x| $x = x }
+ok($x == 0)
+IterTest.new([1]).each1 { |x| $x = x }
+ok($x == 1)
+IterTest.new([2]).each2 { |x| $x = x }
+ok($x == [2])
+IterTest.new([3]).each3 { |x| $x = x }
+ok($x == 3)
+IterTest.new([4]).each4 { |x| $x = x }
+ok($x == 4)
+IterTest.new([5]).each5 { |x| $x = x }
+ok($x == 5)
+IterTest.new([6]).each6 { |x| $x = x }
+ok($x == [6])
+IterTest.new([7]).each7 { |x| $x = x }
+ok($x == 7)
+IterTest.new([8]).each8 { |x| $x = x }
+ok($x == 8)
+
+IterTest.new([[0]]).each0 { |x| $x = x }
+ok($x == [0])
+IterTest.new([[1]]).each1 { |x| $x = x }
+ok($x == 1)
+IterTest.new([[2]]).each2 { |x| $x = x }
+ok($x == [2])
+IterTest.new([[3]]).each3 { |x| $x = x }
+ok($x == 3)
+IterTest.new([[4]]).each4 { |x| $x = x }
+ok($x == [4])
+IterTest.new([[5]]).each5 { |x| $x = x }
+ok($x == 5)
+IterTest.new([[6]]).each6 { |x| $x = x }
+ok($x == [6])
+IterTest.new([[7]]).each7 { |x| $x = x }
+ok($x == 7)
+IterTest.new([[8]]).each8 { |x| $x = x }
+ok($x == [8])
+
+IterTest.new([[0,0]]).each0 { |x| $x = x }
+ok($x == [0,0])
+IterTest.new([[8,8]]).each8 { |x| $x = x }
+ok($x == [8,8])
+
check "bignum"
def fact(n)
return 1 if n == 0
@@ -546,9 +603,9 @@ check "string & char"
ok("abcd" == "abcd")
ok("abcd" =~ "abcd")
ok("abcd" === "abcd")
-ok(("abc" =~ /^$/) == false)
-ok(("abc\n" =~ /^$/) == false)
-ok(("abc" =~ /^d*$/) == false)
+ok("abc" !~ /^$/)
+ok("abc\n" !~ /^$/)
+ok("abc" !~ /^d*$/)
ok(("abc" =~ /d*$/) == 3)
ok("" =~ /^$/)
ok("\n" =~ /^$/)
diff --git a/sample/tsvr.rb b/sample/tsvr.rb
index fbc6545bb5..d6a5620d11 100644
--- a/sample/tsvr.rb
+++ b/sample/tsvr.rb
@@ -13,7 +13,7 @@ while TRUE
ns = gs.accept
print(ns, " is accepted\n")
Thread.start do
- s = ns # save to dynamic variable
+ s = ns # save to thread-local variable
while s.gets
s.write($_)
end