public
Created — forked from apeiros/irb_drop.rb

  • Download Gist
irb_drop.rb
Ruby
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
module Kernel
# usage:
# require 'irb_drop'
# ...do some stuff...
# irb_drop(binding) # irb will open here with the current local variables
# ...continue doing stuff...
def irb_drop(context=nil, *argv)
require 'irb'
require 'pp'
require 'yaml'
original_argv = ARGV.dup
ARGV.replace(argv) # IRB is being stupid
unless defined? ::IRB_SETUP
IRB.setup(nil)
Object.const_set(:IRB_SETUP, true)
end
irb = IRB::Irb.new(IRB::WorkSpace.new(context))
IRB.conf[:IRB_RC].call(irb.context) if IRB.conf[:IRB_RC] # loads the irbrc?
IRB.conf[:MAIN_CONTEXT] = irb.context # why would the main context be set here?
trap("SIGINT") do irb.signal_handle end
ARGV.replace(original_argv)
catch(:IRB_EXIT) do irb.eval_input end
end
module_function :irb_drop
end
 
# cucumber step to go along with it
Then /^drop me into IRB$/ do
irb_drop(self)
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.