Module: InheritableAccessors::InheritableSetAccessor::ClassMethods

Defined in:
lib/inheritable_accessors/inheritable_set_accessor.rb

Instance Method Summary collapse

Instance Method Details

#inheritable_set_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_set_accessor.rb', line 6

def inheritable_set_accessor(name)
  name = name.to_s

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

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

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