Active Support has this code (edited for brevity):
# dependencies.rb ------------------------------------
class Module #:nodoc:
def const_missing(class_id)
Dependencies.load_missing_constant self, class_id
end
end
class Class
def const_missing(class_id)
if [Object, Kernel].include?(self) || parent == self
super
else
...
end
end
end
# intropection.rb ------------------------------------
class Module
def parent
parent_name = name.split('::')[0..-2] * '::'
parent_name.empty? ? Object : parent_name.constantize
end
end
Looks like the condition "[Object, Kernel].include?(self) || parent == self" wants to test whether this is a root class, but no matter which is the intention I wonder:
(1) Since Kernel is a module, is there any chance that self
in Class#const_missing is Kernel?
(2) Can parent == self be true with self != Object?
For (2) I've even tried to contrived things like
class A
A = A
end
that makes A::A == A but has not been able to fool Module#parent. I think "parent == self" is redundant but since it is there I want to be sure I don't miss some edge case.
-- fxn