Module: AttrInheritable::ClassMethods

Defined in:
lib/bufferaffects/attr_inheritable.rb

Instance Method Summary collapse

Instance Method Details

#attr_inheritable(*variables) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bufferaffects/attr_inheritable.rb', line 10

def attr_inheritable(*variables)
  variables.each do |v|
    module_eval %{
      def #{v}
        @#{v} = superclass.#{v} if !instance_variable_defined?(:@#{v}) && superclass.respond_to?(:#{v})
        @#{v} ||= nil
        return @#{v}
      end
    }
  end
end

#attr_inheritable_array(*variables) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bufferaffects/attr_inheritable.rb', line 34

def attr_inheritable_array(*variables)
  variables.each do |v|
    module_eval %{
      def #{v}
        @#{v} = superclass.#{v} if !instance_variable_defined?(:@#{v}) && superclass.respond_to?(:#{v})
        if @#{v} ||= []
          return @#{v}
        end
    }
  end
end

#attr_inheritable_hash(*variables) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bufferaffects/attr_inheritable.rb', line 22

def attr_inheritable_hash(*variables)
  variables.each do |v|
    module_eval %{
      def #{v}
        @#{v} = superclass.#{v} if !instance_variable_defined?(:@#{v}) && superclass.respond_to?(:#{v})
        @#{v} ||= {}
        return @#{v}
      end
    }
  end
end