public
Description: a Ruby VM/interpreter
Homepage: http://rubyex.sairyx.org/
Clone URL: git://github.com/celtic/rubyex.git
rubyex / ruby / test_irb.rb
100755 41 lines (36 sloc) 0.765 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!./ruby
 
input = :continue
line_count = 0
chaining = ""
chaining_mode = false
_ = nil
 
while input == :continue
  line_count += 1
  print "rxi(main):#{line_count}:0#{if chaining_mode; "*"; else ">"; end} "
  input = gets
  chaining_mode = false
 
  if input.nil?
    puts
  else
    input.strip!
    if input.length > 0
      begin
puts "=> " + (_ = eval(chaining + input + "\n")).inspect
chaining = ""
      rescue Exception => e
if e.class == SyntaxError
if e.message.index "unexpected $end"
# This is so not robust.
chaining_mode = true
chaining += "#{input}\n"
else
chaining = ""; puts "#{e.class}: #{e.message}"
end
else
chaining = ""; puts "#{e.class}: #{e.message}"
end
      end
    end
    input = :continue
  end
end