Module: Ergane::Concerns::Inheritance::ClassMethods
- Defined in:
- lib/ergane/concerns/inheritance.rb
Instance Method Summary collapse
- #abstract_class=(value) ⇒ Object
- #abstract_class? ⇒ Boolean
-
#base_class ⇒ Object
Returns the class descending directly from Ergane::Command, or an abstract class, if any, in the inheritance hierarchy.
Instance Method Details
#abstract_class=(value) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/ergane/concerns/inheritance.rb', line 11 def abstract_class=(value) @abstract_class = value # Re-run registration so the command leaves (or rejoins) its # registry to match its new abstract state. register! if self < Ergane::Command && respond_to?(:register!, true) end |
#abstract_class? ⇒ Boolean
18 19 20 |
# File 'lib/ergane/concerns/inheritance.rb', line 18 def abstract_class? @abstract_class == true end |
#base_class ⇒ Object
Returns the class descending directly from Ergane::Command, or an abstract class, if any, in the inheritance hierarchy.
If A extends Command, A.base_class returns A. If B < A through some hierarchy, B.base_class returns A. If A is abstract, both B.base_class and C.base_class return B.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ergane/concerns/inheritance.rb', line 28 def base_class unless self < Ergane::Command raise Ergane::Error, "#{name} doesn't belong in a hierarchy descending from Ergane::Command" end if superclass == Ergane::Command || superclass.abstract_class? self else superclass.base_class end end |