diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-12-19 20:42:50 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-12-19 20:42:50 +0000 |
| commit | 99b1964956339d6968377cd0e1f2f5999a88e7fe (patch) | |
| tree | df1d1c9084747f774a22748f755ae7aea891e4c2 /sample | |
| parent | 252d08dd961deed96a6c37d3e014d78abc64b46d (diff) | |
| download | ruby-99b1964956339d6968377cd0e1f2f5999a88e7fe.tar.gz ruby-99b1964956339d6968377cd0e1f2f5999a88e7fe.tar.xz ruby-99b1964956339d6968377cd0e1f2f5999a88e7fe.zip | |
Improve.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
| -rw-r--r-- | sample/eval.rb | 15 | ||||
| -rw-r--r-- | sample/fact.rb | 5 |
2 files changed, 9 insertions, 11 deletions
diff --git a/sample/eval.rb b/sample/eval.rb index 8b582b0fd..90b839e87 100644 --- a/sample/eval.rb +++ b/sample/eval.rb @@ -1,13 +1,13 @@ line = '' -indent=0 +indent = 0 $stdout.sync = TRUE print "ruby> " -while TRUE +loop do l = gets - unless l - break if line == '' + if l.nil? + break if line.empty? else - line = line + l + line += l if l =~ /,\s*$/ print "ruby| " next @@ -32,10 +32,9 @@ while TRUE begin print eval(line).inspect, "\n" rescue ScriptError, StandardError - $! = 'exception raised' unless $! - print "ERR: ", $!, "\n" + printf "ERR: %s\n", $! || 'exception raised' end - break if not l + break if l.nil? line = '' print "ruby> " end diff --git a/sample/fact.rb b/sample/fact.rb index 1462a6923..d8147a40f 100644 --- a/sample/fact.rb +++ b/sample/fact.rb @@ -1,9 +1,8 @@ def fact(n) return 1 if n == 0 f = 1 - while n>0 - f *= n - n -= 1 + n.downto(1) do |i| + f *= i end return f end |
