Guest User

Untitled

a guest
May 27th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. module Kernel
  2. # usage:
  3. # require 'irb_drop'
  4. # ...do some stuff...
  5. # irb_drop(binding) # irb will open here with the current local variables
  6. # ...continue doing stuff...
  7. def irb_drop(context=nil, *argv)
  8. require 'irb'
  9. require 'pp'
  10. require 'yaml'
  11. original_argv = ARGV.dup
  12. ARGV.replace(argv) # IRB is being stupid
  13. unless defined? ::IRB_SETUP
  14. IRB.setup(nil)
  15. Object.const_set(:IRB_SETUP, true)
  16. end
  17. irb = IRB::Irb.new(IRB::WorkSpace.new(context))
  18. IRB.conf[:IRB_RC].call(irb.context) if IRB.conf[:IRB_RC] # loads the irbrc?
  19. IRB.conf[:MAIN_CONTEXT] = irb.context # why would the main context be set here?
  20. trap("SIGINT") do irb.signal_handle end
  21. ARGV.replace(original_argv)
  22. catch(:IRB_EXIT) do irb.eval_input end
  23. end
  24. module_function :irb_drop
  25. end
  26.  
  27. # cucumber step to go along with it
  28. Then /^drop me into IRB$/ do
  29. irb_drop(self)
  30. end
Add Comment
Please, Sign In to add comment