different namespaces for classes defined within instance_eval #276

Closed
thinkerbot opened this Issue May 1, 2010 · 1 comment

Projects

None yet

2 participants

@thinkerbot

I really don't know the truly 'correct' behavior here, but as an FYI rubinius determines the parent constant for classes defined within an instance_eval string while MRI does not. I posted this to ruby-talk to see if anyone had opinions but I'm re-posting here in case you consider it an issue. (http://groups.google.com/group/ruby-talk-google/browse_thread/thread/58b9f8e223e9a98d)

[script.rb]
obj = Object.new

obj.instance_eval do
  class A; end
  puts A
end
puts A rescue puts $!.message

obj.instance_eval %q{
  class B; end
  puts B
}
puts B rescue puts $!.message

And here is the output using several implementations:

% rvm ruby script.rb 
jruby-1.4.0: jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java] 
A
A
#<Class:01x5ec24193>::B
uninitialized constant B
rbx-1.0.0-rc4: rubinius 1.0.0-rc4 (1.8.7 release 2010-03-31 JI) [x86_64-apple-darwin10.3.0] 
A
A
B
B
ruby-1.8.7-p249: ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10.2.0] 
A
A
#<Class:0x10019c368>::B
uninitialized constant B
ruby-1.9.1-p378: ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.2.0] 
#<Class:0x00000100847ed0>::A
uninitialized constant A
#<Class:0x00000100847ed0>::B
uninitialized constant B

I'm on OSX 10.6.2.

@evanphx
Rubinius member

Use the receiver metaclass as the scoped class. Closed by 28fef11.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment