Skip to content

Instantly share code, notes, and snippets.

@jschementi
Created May 22, 2009 22:17
Show Gist options
  • Save jschementi/116393 to your computer and use it in GitHub Desktop.
Save jschementi/116393 to your computer and use it in GitHub Desktop.
TOPLEVEL_BINDING = binding unless defined?(TOPLEVEL_BINDING)
def repl(scope = TOPLEVEL_BINDING)
Repl.start(scope)
end
module Repl
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
end
@rdp
Copy link

rdp commented May 19, 2010

run this code somehow, then later call repl(binding)
you could also embed irb if you need more than one liners http://jameskilton.com/2009/04/02/embedding-irb-into-your-ruby-application/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment