Module: Repl

Defined in:
lib/faster_rubygems/ir_session.rb

Class Method Summary collapse

Class Method Details

.start(scope = TOPLEVEL_BINDING) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/faster_rubygems/ir_session.rb', line 8

def self.start(scope = TOPLEVEL_BINDING)
  quitstr = ['quit', 'exit', '']
  while true
    stack = eval("caller[3..-1]", scope)
    print "\n#{stack.first}\n" if stack and not stack.empty?
    print 'rb> '
    input = gets.strip rescue 'quit'
    break if quitstr.include?(input)
    puts "=> #{
      begin
        eval(input, scope).inspect
      rescue LoadError => le
        puts le.inspect
      rescue SyntaxError => se
        puts se.inspect
      rescue => e
        puts e.inspect
      end
    }"
  end
end