From: Jeremy Evans Date: 2011-07-04T11:16:39+09:00 Subject: [ruby-core:37765] [Ruby 1.9 - Bug #3768] Constant Lookup doesn't work in a subclass of BasicObject Issue #3768 has been updated by Jeremy Evans. I disagree that the behavior is "clearly broken". Just like methods defined in Object don't apply to BasicObject, you shouldn't expect constants defined in Object to apply to BasicObject. You assume that normal constant lookup is always desired in BasicObject subclasses. While true in some cases, it is not necessarily true in all. Take this simple case: class S < BasicObject def method_missing(m) m end def self.const_missing(m) m end end Basically, the programmer desires both that both method calls and constant references return symbols: S.new.instance_eval{puts} # => :puts S.new.instance_eval{Object} # => :Object With your approach, you would get ::Object instead of :Object for the second line. Just like the puts method doesn't exist in BasicObject instances, the Object constant doesn't exist in BasicObject. Your recommendation would remove the ability programmers currently have to choose how to implement constant lookup in their BasicObject subclasses. Your recommendation assumes that all users want normal constant lookup in a BasicObject subclass. However, the fact that they are using BasicObject is an indication that they don't want normal method lookup (no methods from Object or Kernel), so I think the assumption that they definitely want normal constant lookup is invalid. I agree that adding documentation to BasicObject related to this would be beneficial, perhaps you should submit a documentation patch? ---------------------------------------- Bug #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: ruby -v: 1.9.2-p0 =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