diff options
Diffstat (limited to 'sample/eval.rb')
| -rw-r--r-- | sample/eval.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/sample/eval.rb b/sample/eval.rb index 216bf8ca39..ed4b7c3de5 100644 --- a/sample/eval.rb +++ b/sample/eval.rb @@ -1,18 +1,18 @@ line = '' -indent=0 -$stdout.sync = TRUE +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 end - if l =~ /^\s*(class|module|def|if|case|while|for|begin)\b[^_]/ + if l =~ /^\s*(class|module|def|if|unless|case|while|until|for|begin)\b[^_]/ indent += 1 end if l =~ /^\s*end\b[^_]/ @@ -31,11 +31,10 @@ while TRUE end begin print eval(line).inspect, "\n" - rescue - $! = 'exception raised' unless $! - print "ERR: ", $!, "\n" + rescue ScriptError, StandardError + printf "ERR: %s\n", $! || 'exception raised' end - break if not l + break if l.nil? line = '' print "ruby> " end |
