Permalink
Browse files

- add irb example

  • Loading branch information...
1 parent 4a45611 commit d5c3bd8af0fc99eaabaee2b39c8014a10ec9b7db @jordansissel committed Apr 13, 2011
Showing with 27 additions and 0 deletions.
  1. +27 −0 irb-example.rb
View
@@ -0,0 +1,27 @@
+# Code from http://jameskilton.com/2009/04/02/embedding-irb-into-your-ruby-application/
+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
+
+IRB.start_session(binding)

0 comments on commit d5c3bd8

Please sign in to comment.