From: Bob X Date: 2002-06-14T06:46:59+09:00 Subject: Re: Embedding irb Into an FXRuby app would be even better. : ) Joel VanderWerf wrote: > Gilles Filippini wrote: > >>Hi, >> >>It must be a basic question, but I didn't find any answer: >>How to embed an IRB session into a ruby app ? > > > This is one way to do it for a command line app (i.e., without changing > stdin/out). It works well, but I do wish IRB made this a bit easier. The > obj argument to start_session will be self when the session starts up. > > require 'irb' > require 'irb/completion' > > module IRB > def IRB.start_session(obj) > unless $irb > IRB.initialize nil > ## maybe set some opts here, as in parse_opts in irb/init.rb? > IRB.load_modules > end > > workspace = WorkSpace.new(obj) > > if @CONF[:SCRIPT] ## normally, set by parse_opts > $irb = Irb.new(workspace, @CONF[:SCRIPT]) > else > $irb = Irb.new(workspace) > end > > @CONF[:IRB_RC].call($irb.context) if @CONF[:IRB_RC] > @CONF[:MAIN_CONTEXT] = $irb.context > > trap("INT") do > $irb.signal_handle > end > > catch(:IRB_EXIT) do > $irb.eval_input > end > print "\n" > > ## might want to reset your app's interrupt handler here > end > end >