Given a parent class is there a way to insert code for every subclass on load? ie.
Given: ParentClass
, how do I insert code like so:
class ChildClass < ParentClass
execute_function
...
end
for all child classes of ParentClass
?
In the ParentClass
override the inherited method
class ParentClass
def self.inherited(subclass)
execute_function
super
end
...
end
See: http://ruby-doc.org/core-2.0/Class.html#method-i-inherited
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With