From d5c3bd8af0fc99eaabaee2b39c8014a10ec9b7db Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Wed, 13 Apr 2011 14:36:07 -0700 Subject: [PATCH] - add irb example --- irb-example.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 irb-example.rb diff --git a/irb-example.rb b/irb-example.rb new file mode 100644 index 0000000..6290bdf --- /dev/null +++ b/irb-example.rb @@ -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)