Created
October 31, 2015 18:54
-
-
Save katpadi/1ada972a12ecfb1cfa58 to your computer and use it in GitHub Desktop.
active_record_descendant_class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns the class descending directly from ActiveRecord::Base in the inheritance hierarchy. | |
def active_record_descendant_class(klass) | |
if klass == ActiveRecord::Base || klass.superclass == ActiveRecord::Base | |
klass | |
elsif klass.superclass.nil? | |
fail "#{name} doesn't belong in a hierarchy descending from ActiveRecord" | |
else | |
active_record_descendant_class(klass.superclass) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment