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

IRB with binding to another object. #384

Closed
dekz opened this issue Nov 10, 2012 · 4 comments
Closed

IRB with binding to another object. #384

dekz opened this issue Nov 10, 2012 · 4 comments

Comments

@dekz
Copy link
Contributor

dekz commented Nov 10, 2012

Apparently MRI supports multiple IRB sessions and supports the ability to open an IRB session within the context of another object (ie using that objects binding). It seems as if JRuby has problems with this and results in some form of half half mode, but the actual irb context defaults back to a "main" Object.

require 'irb'
obj = Object.new
# Override the objects pretty name formats
obj.instance_eval do
  def inspect; "Test"; end
  def to_s; "Test"; end
end
ARGV.clear
IRB.setup nil

irb = IRB::Irb.new(IRB::WorkSpace.new(obj))
IRB.conf[:MAIN_CONTEXT] = irb.context

# Start the IRB session with this objects binding, passing in nil for file
require 'irb/ext/multi-irb'
IRB.irb nil, obj

Now an IRB session should be started using obj's binding. Unforntunately JRuby defaults back to "main" Object, but the prompt has picked up the correct object to use (you can see "Test" in the prompt).

irb#1(Test):001:0> self
=> main

MRI looks like the following:

irb#1(Test):001:0> self
=> Test

Tested using MRI 1.9.3-p194 and JRuby 1.7.0 release.

@dekz
Copy link
Contributor Author

dekz commented Nov 10, 2012

Looks like the MAIN_CONTEXT workspace binding is confused:
JRuby 1.7.0:

IRB.conf[:MAIN_CONTEXT].workspace.binding.eval "self"
# => main

MRI 1.9.3

IRB.conf[:MAIN_CONTEXT].workspace.binding.eval "self"
# => Test

The bindings are actually different objects on JRuby, ie the workspace main object binding ("Test") differs to the workspace binding ("main). This seems to happen in both JRuby and MRI.

# JRuby 1.7.0
IRB.conf[:MAIN_CONTEXT].workspace.main.instance_eval { binding }
#=> #<Binding:0x54f169>
IRB.conf[:MAIN_CONTEXT].workspace.binding
#=> #<Binding:0x15c313da>

# MRI 1.9.3
IRB.conf[:MAIN_CONTEXT].workspace.main.instance_eval { binding }
#=> #<Binding:0x007ffb8d85ce48>
IRB.conf[:MAIN_CONTEXT].workspace.binding
#=> #<Binding:0x007ffb8c30c868>

Here is the output of self binding evaluation in JRuby:

IRB.conf[:MAIN_CONTEXT].workspace.main.instance_eval { binding.eval "self" }
#=> Test
IRB.conf[:MAIN_CONTEXT].workspace.binding.eval "self"
#=> main

@headius
Copy link
Member

headius commented Nov 10, 2012

Could be a known issue where cloned bindings do not actually copy their
state...or might be unrelated.

Apparently MRI supports multiple IRB sessions and supports the ability to
open an IRB session within the context of another object (ie using that
objects binding). It seems as if JRuby has problems with this and results
in some form of half half mode, but the actual irb context defaults back to
a "main" Object.

require 'irb'
obj = Object.new

Override the objects pretty name formats

obj.instance_eval do
def inspect; "Test"; end
def to_s; "Test"; end
end
ARGV.clear
IRB.setup nil

irb = IRB::Irb.new(IRB::WorkSpace.new(obj))
IRB.conf[:MAIN_CONTEXT] = irb.context

Start the IRB session with this objects binding, passing in nil for file

require 'irb/ext/multi-irb'
IRB.irb nil, obj

Now an IRB session should be started using obj's binding. Unforntunately
JRuby defaults back to "main" Object, but the prompt has picked up the
correct object to use (you can see "Test" in the prompt).

irb#1(Test):001:0> self
=> main

MRI looks like the following:

irb#1(Test):001:0> self
=> Test

Tested using MRI 1.9.3-p194 and JRuby 1.7.0 release.


Reply to this email directly or view it on GitHubhttps://github.com//issues/384.

@MSNexploder
Copy link
Contributor

Looks like this is working correctly on master

jruby --version
jruby 9.0.0.0-SNAPSHOT (2.2.0p0) 2015-01-01 fb9199f Java HotSpot(TM) 64-Bit Server VM 25.25-b02 on 1.8.0_25-b17 +jit [darwin-x86_64]

...

irb#1(Test):001:0> self
=> Test
irb#1(Test):002:0> IRB.conf[:MAIN_CONTEXT].workspace.binding.eval "self"
=> Test
irb#1(Test):003:0> 

@enebo enebo added this to the Won't Fix milestone Feb 17, 2017
@enebo
Copy link
Member

enebo commented Feb 17, 2017

This works in 9k and we will never fix this in 1.7.x as it is winding down....resolving.

@enebo enebo closed this as completed Feb 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants