Subclasses_of core method

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| })
klasses = method_name.to_s.scan(subclasses_for_scan)

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
also I would like to move subclasses_for_scan implementation outside
this method, to make only one call.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs