From: Jeremy Evans Date: 2011-07-06T00:34:31+09:00 Subject: [ruby-core:37801] [Ruby 1.9 - Feature #3768] Constant Lookup doesn't work in a subclass of BasicObject Issue #3768 has been updated by Jeremy Evans. Thomas, your example works on 1.9.2p180: $ ruby -v ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-openbsd4.9] $ cat > q.rb class R end class Q < BasicObject def r; R.new; end end $ irb irb(main):001:0> module M; eval(File.read('q.rb')); end => nil irb(main):002:0> M::Q.new.r => # It doesn't work if you change R.new to ::R.new, but that's to be expected (it would be the same if Q descended from Object). It even works if R and Q are defined in separate files: $ cat > r.rb class R end $ cat > q.rb class Q < BasicObject def r; R.new; end end $ irb irb(main):001:0> module M; eval(File.read('r.rb')); end => nil irb(main):002:0> module M; eval(File.read('q.rb')); end => nil irb(main):003:0> M::Q.new.r => # The behavior is still the same on "ruby 1.9.3dev (2011-02-28 trunk 30975) [x86_64-openbsd4.9]", so if it no longer works, it must have changed in the last few months. I agree that constant lookup and method lookup are not the same thing, and should not necessarily be treated the same way. However, I think the purpose of BasicObject is, to the extent possible, remove the default behavior that most objects have in order to allow the programmer to define their own behavior. Therefore, I think allowing the programmer control over constant lookup in BasicObject subclasses makes sense. ---------------------------------------- Feature #3768: Constant Lookup doesn't work in a subclass of BasicObject http://redmine.ruby-lang.org/issues/3768 Author: Thomas Sawyer Status: Rejected Priority: Normal Assignee: Yukihiro Matsumoto Category: lib Target version: =begin ruby-1.9.2-p0 > module M ruby-1.9.2-p0 ?> end => nil ruby-1.9.2-p0 > class X < BasicObject ruby-1.9.2-p0 ?> include M ruby-1.9.2-p0 ?> end NameError: uninitialized constant X::M from (irb):4:in `' from (irb):3 from /home/trans/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `
' =end -- http://redmine.ruby-lang.org