module Hooks::InheritableAttribute
def inheritable_attr(name)
Cat.drinks #=> ["Becks"]
and then, later
self.drinks << "Fireman's 4"
class Garfield < Cat
self.drinks = ["Becks"]
inheritable_attr :drinks
class Cat
Example:
chain. Note that you have to initialize the inheritable attribute.
attributes. This is especially helpful with arrays or hashes that are extended in the inheritance
Creates an inheritable attribute with accessors in the singleton class. Derived classes inherit the
def inheritable_attr(name) instance_eval %Q{ def #{name}=(v) @#{name} = v end def #{name} return @#{name} unless superclass.respond_to?(:#{name}) and value = superclass.#{name} @#{name} ||= value.clone # only do this once. end } end