Skip to content

Instantly share code, notes, and snippets.

@katpadi
Created October 31, 2015 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katpadi/1ada972a12ecfb1cfa58 to your computer and use it in GitHub Desktop.
Save katpadi/1ada972a12ecfb1cfa58 to your computer and use it in GitHub Desktop.
active_record_descendant_class
# 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