Created
May 22, 2009 22:17
-
-
Save jschementi/116393 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/