You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Thanks for reporting your issue! This is one of my 20 active issues. Use that link to check how soon your issue will be answered. Don't forget to check your issue against this project's CONTRIBUTING.md. Cheers.
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. TryingRipl.config[:binding]
didn't help either. The root of the problem, I think, is this code:Ripl.start
ends up callingRipl.shell
. The first time throughShell.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: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 theeval("_ = Ripl.shell.result", @binding)
calls don't work properly. I hacked in a setter for@shell
to get around that.The text was updated successfully, but these errors were encountered: