Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit eeb8880120abf19c99fa57cee3c33ee2b35758c2 0 parents
mpd authored
Showing with 40 additions and 0 deletions.
  1. +16 −0 README.md
  2. +24 −0 internal_irb
16 README.md
@@ -0,0 +1,16 @@
+Wut?
+====
+
+Just a small chunk of code taken from a blog post at http://jameskilton.com/2009/04/02/embedding-irb-into-your-ruby-application/ (which itself was taken from the ruby-debug gem) to drop into an irb session at any point in a ruby program.
+
+How?
+====
+
+0. `require` this file somewhere in your app.
+1. `IRB.start_session(binding)` in your code will drop into irb immediately.
+
+
+Huh?
+====
+
+It works on my machine. ¯\(°_o)/¯
24 internal_irb
@@ -0,0 +1,24 @@
+require 'irb'
+
+module IRB # :nodoc:
+ def self.start_session(binding)
+ unless @__initialized
+ args = ARGV
+ ARGV.replace(ARGV.dup)
+ IRB.setup(nil)
+ ARGV.replace(args)
+ @__initialized = true
+ end
+
+ workspace = WorkSpace.new(binding)
+
+ irb = Irb.new(workspace)
+
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
+ @CONF[:MAIN_CONTEXT] = irb.context
+
+ catch(:IRB_EXIT) do
+ irb.eval_input
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.