instance method base_class

Ruby on Rails 6.0.6

Since v3.2.22.5 Last seen in v6.1.7.10

Available in: v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10

Signature

base_class()

Returns the class descending directly from ActiveRecord::Base, or an abstract class, if any, in the inheritance hierarchy.

If A extends ActiveRecord::Base, A.base_class will return A. If B descends from A through some arbitrarily deep hierarchy, B.base_class will return A.

If B < A and C < B and if A is an abstract_class then both B.base_class and C.base_class would return B as the answer since A is an abstract_class.

Source
# File activerecord/lib/active_record/inheritance.rb, line 99
      def base_class
        unless self < Base
          raise ActiveRecordError, "#{name} doesn't belong in a hierarchy descending from ActiveRecord"
        end

        if superclass == Base || superclass.abstract_class?
          self
        else
          superclass.base_class
        end
      end

Defined in activerecord/lib/active_record/inheritance.rb line 99 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Inheritance::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close