From: Joel VanderWerf Date: 2004-05-05T03:15:57+09:00 Subject: Re: Can a program be made to drop into irb? Joel VanderWerf wrote: > Ara's idea to pass a binding to Workspace.new is great. Changes to > locals are even persistent after you leave the shell. I'm puzzled about > why that works--maybe irb detects that the object is a binding? Yes, that's what irb does. In irb/workspace.irb: module IRB class WorkSpace # create new workspace. set self to main if specified, otherwise # inherit main from TOPLEVEL_BINDING. def initialize(*main) if main[0].kind_of?(Binding) @binding = main.shift So you can get two useful effects with WorkSpace.new: WorkSpace.new(obj) Makes obj the self of a new workspace. WorkSpace.new(b, obj) Makes obj the self of a new workspace, and uses b as the binding.