Skip to content

Commit a5f64bf

Browse files
Merge pull request rails#49004 from andrewn617/improve-base-class-documentation
Improve the documentation for ActiveRecord::Inheritance#base_class
2 parents be2c632 + 4627995 commit a5f64bf

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

activerecord/lib/active_record/inheritance.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,24 @@ def finder_needs_type_condition? # :nodoc:
9494
:true == (@finder_needs_type_condition ||= descends_from_active_record? ? :false : :true)
9595
end
9696

97-
# Returns the class descending directly from ActiveRecord::Base, or
98-
# an abstract class, if any, in the inheritance hierarchy.
97+
# Returns the first class in the inheritance hierarchy that descends from either an
98+
# abstract class or from <tt>ActiveRecord::Base</tt>.
9999
#
100-
# If A extends ActiveRecord::Base, A.base_class will return A. If B descends from A
101-
# through some arbitrarily deep hierarchy, B.base_class will return A.
100+
# Consider the following behaviour:
102101
#
103-
# If B < A and C < B and if A is an abstract_class then both B.base_class
104-
# and C.base_class would return B as the answer since A is an abstract_class.
102+
# class ApplicationRecord < ActiveRecord::Base
103+
# self.abstract_class = true
104+
# end
105+
# class Shape < ApplicationRecord
106+
# self.abstract_class = true
107+
# end
108+
# Polygon = Class.new(Shape)
109+
# Square = Class.new(Polygon)
110+
#
111+
# ApplicationRecord.base_class # => ApplicationRecord
112+
# Shape.base_class # => Shape
113+
# Polygon.base_class # => Polygon
114+
# Square.base_class # => Polygon
105115
attr_reader :base_class
106116

107117
# Returns whether the class is a base class.

0 commit comments

Comments
 (0)