[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / sample / eval.rb
blobed4b7c3de5090388a60fb441e8ca8d885e45f438
1 line = ''
2 indent = 0
3 $stdout.sync = true
4 print "ruby> "
5 loop do
6   l = gets
7   if l.nil?
8     break if line.empty?
9   else
10     line += l
11     if l =~ /,\s*$/
12       print "ruby| "
13       next
14     end
15     if l =~ /^\s*(class|module|def|if|unless|case|while|until|for|begin)\b[^_]/
16       indent += 1
17     end
18     if l =~ /^\s*end\b[^_]/
19       indent -= 1
20     end
21     if l =~ /\{\s*(\|.*\|)?\s*$/
22       indent += 1
23     end
24     if l =~ /^\s*\}/
25       indent -= 1
26     end
27     if indent > 0
28       print "ruby| "
29       next
30     end
31   end
32   begin
33     print eval(line).inspect, "\n"
34   rescue ScriptError, StandardError
35     printf "ERR: %s\n", $! || 'exception raised'
36   end
37   break if l.nil?
38   line = ''
39   print "ruby> "
40 end
41 print "\n"