Skip to content

Commit cd0e71a

Browse files
committed
Simple script to start a irb session
1 parent 6a75cc5 commit cd0e71a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

ruby/debug.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'irb'
2+
3+
# source: http://jameskilton.com/2009/04/02/embedding-irb-into-your-ruby-application/
4+
module IRB # :nodoc:
5+
def self.start_session(binding)
6+
unless @__initialized
7+
args = ARGV
8+
ARGV.replace(ARGV.dup)
9+
IRB.setup(nil)
10+
ARGV.replace(args)
11+
@__initialized = true
12+
end
13+
14+
workspace = WorkSpace.new(binding)
15+
irb = Irb.new(workspace)
16+
17+
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
18+
@CONF[:MAIN_CONTEXT] = irb.context
19+
20+
catch(:IRB_EXIT) do
21+
irb.eval_input
22+
end
23+
end
24+
end
25+
26+
def hack(binding)
27+
IRB.start_session(binding)
28+
end
29+
30+
# TODO: get binding without sending it as a parameter
31+
# https://github.com/quix/binding_of_caller

0 commit comments

Comments
 (0)