Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ripl.start returns the same shell on multiple invocations #43

Open
peter-ellis opened this issue Jul 17, 2016 · 1 comment
Open

Ripl.start returns the same shell on multiple invocations #43

peter-ellis opened this issue Jul 17, 2016 · 1 comment

Comments

@peter-ellis
Copy link

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.

@cldwalker
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants