-
Notifications
You must be signed in to change notification settings - Fork 20
Description
I have a program that needs to jump in and out of the shell from different text files--each of which has its own separate Ruby binding environment. I could not get IRB to work right for various reasons and Pry seemed like overkill. So Ripl is the perfect fit--thanks for making it.
For my purposes I first tried Ripl.start :binding => my_binding. As hinted above, the workflow is that the user enters Ripl, does some stuff, and exits. Then without leaving the program the user enters Ripl again from a different context (i.e., different binding) to do other stuff. This jumping in and out of different bindings might happen several times.
The problem is that I quickly learned that with Ripl.start I kept finding myself in the same binding (the first one) on the second or third invocation, even if setting the :binding option. Trying Ripl.config[:binding] didn't help either. The root of the problem, I think, is this code:
def self.shell(options={})
@shell ||= Shell.create(config.merge!(options))
end
Ripl.start ends up calling Ripl.shell. The first time through Shell.create is called and @shell is set. Any subsequent invocation just returns @shell instead of creating a new shell.
I'm not sure what the best solution should be (or else I might have a pull request for you). My workaround was to start things from a lower level by going directly to Ripl::Shell with something like this:
Ripl::Shell.create(options).loop
The options contain the binding and some other stuff. I also had to trigger the .riplrc to load. This works but the main downside is that @shell is not set so the eval("_ = Ripl.shell.result", @binding) calls don't work properly. I hacked in a setter for @shell to get around that.