Module: InheritableAccessors::InheritableHashAccessor::ClassMethods

Defined in:
lib/inheritable_accessors/inheritable_hash_accessor.rb

Instance Method Summary collapse

Instance Method Details

#inheritable_hash_accessor(name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/inheritable_accessors/inheritable_hash_accessor.rb', line 6

def inheritable_hash_accessor(name)
  name = name.to_s

  module_eval <<-METHODS
    def self.inheritable_hash?
      true
    end

    def self.#{name}
      @__#{name}__ ||= begin
        if superclass.respond_to?(:inheritable_hash?)
          superclass.#{name}.inherit_copy
        else
          ::InheritableAccessors::InheritableHash.new
        end
      end
    end

    def #{name}
      @__#{name}__ ||= self.class.#{name}.inherit_copy
    end
  METHODS
end