I wanted to have irb start its session on an object other than the
toplevel. I found a solution that I think is nicer than any I could
find elsewhere. The idea is to hook into IRB::Irb#initialize and
insert the WorkSpace object that you want.
require "irb" class IRB::Irb alias initialize_orig initialize def initialize(workspace = nil, *args)
default = IRB.conf[:DEFAULT_OBJECT]
workspace ||= IRB::WorkSpace.new default if default
Now, if your .irbrc sets IRB.conf[:DEFAULT_OBJECT], that becomes the
initial object for the irb session.
I am tempted to propose this as a change to irb. Thoughts?