lib/trust/inheritable_attribute.rb
# Creates an inheritable attribute with accessors in the singleton class. 
# 
# Derived classes inherit the attributes. This is especially helpful with arrays or hashes that 
# are extended in the inheritance chain. Note that you have to initialize the inheritable attribute.
#
# === Example
#
#   class Cat
#     inheritable_attr :drinks
#     self.drinks = ["Becks"]
#
#   class Garfield < Cat
#     self.drinks << "Fireman's 4"
#
# and then, later
#
#   Cat.drinks      #=> ["Becks"]
#   Garfield.drinks #=> ["Becks", "Fireman's 4"]
Creates an inheritable attribute with accessors in the singleton class.
Derived classes inherit the attributes. This is especially helpful with arrays or hashes that
are extended in the inheritance chain. Note that you have to initialize the inheritable attribute.

Example

class Cat
inheritable_attr :drinks
self.drinks = ["Becks"]

class Garfield < Cat
self.drinks << "Fireman's 4"

and then, later


Creates an inheritable attribute with accessors in the singleton class . Derived classes inherit the attributes . This is especially helpful with arrays or hashes that are extended in the inheritance chain . Note that you have to initialize the inheritable attribute . Example class Cat inheritable_attr : drinks self . drinks = [ " Becks " ] class Garfield < Cat self . drinks << " Fireman ' s 4 " and then later
def inheritable_attr(name, options = {})
        src = <<-end_src
          def #{name}=(v)
            @#{name} = v
          end
          def #{name}
            return @#{name} unless superclass.respond_to?(:#{name}) and value = superclass.#{name}
            @#{name} ||= ::Trust::InheritableAttribute::deep_copy(value) # only do this once.
          end
        end_src
        instance_eval src, __FILE__, __LINE__
        if !options.key?(:instance_writer) || options[:instance_writer]
          src = <<-end_src
            def #{name}=(v)
              self.class.#{name} = v
            end
          end_src
          class_eval src, __FILE__, __LINE__
        end
        if !options.key?(:instance_reader) || options[:instance_reader]
          src = <<-end_src
            def #{name}
              self.class.#{name}
            end
          end_src
          class_eval src, __FILE__, __LINE__
        end
      end
def inheritable_attr ( name , options = { } ) src = <<-end_src 
          def  #{ name } =(v)
            @ #{ name }  = v
          end

          def  #{ name } 
            return @ #{ name }  unless superclass.respond_to?(: #{ name } ) and value = superclass. #{ name } 
            @ #{ name }  ||= ::Trust::InheritableAttribute::deep_copy(value) # only do this once.
          end
         end_src instance_eval src , __FILE__ , __LINE__ if ! options . key? ( :instance_writer ) || options [ :instance_writer ] src = <<-end_src 
            def  #{ name } =(v)
              self.class. #{ name }  = v
            end
           end_src class_eval src , __FILE__ , __LINE__ end if ! options . key? ( :instance_reader ) || options [ :instance_reader ] src = <<-end_src 
            def  #{ name } 
              self.class. #{ name } 
            end
           end_src class_eval src , __FILE__ , __LINE__ end end
Creates an inheritable attribute with accessors in the singleton class.
Creates an inheritable attribute with accessors in the singleton class .
name
options