# About const\_missing

**URL:** <https://www.ruby-forum.com/t/about-const-missing/119861>\
**Category:** Ruby\
**Created:** [November 11, 2007, 1:43pm UTC](https://www.ruby-forum.com/t/about-const-missing/119861 "2007-11-11T13:43:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [November 11, 2007, 1:43pm UTC](https://www.ruby-forum.com/t/about-const-missing/119861/1 "2007-11-11T13:43:48Z")

</div>

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
