In irb I can create an object and then create a new subsession with
that object as the context.
For example in irb I can type
$psauto = PSAuto::Automator.new
irb $psauto
Now I can call all the methids of $psauto without having to type the
‘$psauto’ each time.
Is it possible to put these two lines into an irb config file so that
I do not have to type them every time I start irb?
yes I am using .irbrc, but it doesn’t work when you pur
‘irb $psauto’ in it. At least it doesn’t work for me
Try this in .irbrc:
module IRB
def IRB.start_session(*args)
unless $irb
IRB.setup nil
end
workspace = WorkSpace.new(*args)
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
custom_configuration if defined?(IRB.custom_configuration)
catch :IRB_EXIT do
$irb.eval_input
end
end
end
x = Object.new
puts “\nStarted irb shell for x”
IRB.start_session(x)
However, I googled “IRB.start_session” and found some other interesting
post and replies (all by you I think!); and I can see other things are
possible.
I’m going to look at this again tomorrow.
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
custom_configuration if defined?(IRB.custom_configuration)
catch :IRB_EXIT do
$irb.eval_input
end
end
end
x = Object.new
puts “\nStarted irb shell for x”
IRB.start_session(x)
However, I googled “IRB.start_session” and found some other interesting
post and replies (all by you I think!); and I can see other things are
possible.
I’m going to look at this again tomorrow.