# Subclasses\_of core method

**URL:** <https://www.ruby-forum.com/t/subclasses-of-core-method/127813>\
**Category:** Rails\
**Created:** [February 1, 2008, 2:35pm UTC](https://www.ruby-forum.com/t/subclasses-of-core-method/127813 "2008-02-01T14:35:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![crossblaim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@crossblaim](https://www.ruby-forum.com/u/crossblaim)\
**Post date:** [February 1, 2008, 2:35pm UTC](https://www.ruby-forum.com/t/subclasses-of-core-method/127813/1 "2008-02-01T14:35:12Z")

</div>

class Account \< ActiveRecord::Base

# Catch-all for methods like is\_admin\_or\_operator.

def method\_missing(method\_name, \*arguments)  
return super unless method\_name.to\_s =~ /\Ais\_/  
subclasses\_for\_scan =  
Regexp.union(\*Object.subclasses\_of(Account).map { |c|  
c.name.downcase })  
klasses = method\_name.to\_s.scan(subclasses\_for\_scan)  
klasses.include?(self.class.to\_s.downcase)  
end

hello.  
I’m trying to use the above code but I have a problem with  
subclasses\_of, returning random results, probably because of model  
load order.

is there a stable way to fetch every subclass of Account without  
including every subclass in the same file or by parsing model source  
files?  
also I would like to move subclasses\_for\_scan implementation outside  
this method, to make only one call.

thanks.
