Module: ClassLevelInheritableAttributes::ClassMethods

Defined in:
lib/darwinning/organism.rb

Instance Method Summary collapse

Instance Method Details

#inheritable_attributes(*args) ⇒ Object


8
9
10
11
12
13
14
15
16
17
# File 'lib/darwinning/organism.rb', line 8

def inheritable_attributes(*args)
  @inheritable_attributes ||= [:inheritable_attributes]
  @inheritable_attributes += args
  args.each do |arg|
    class_eval %(
      class << self; attr_accessor :#{arg} end
    )
  end
  @inheritable_attributes
end

#inherited(subclass) ⇒ Object


19
20
21
22
23
24
# File 'lib/darwinning/organism.rb', line 19

def inherited(subclass)
  @inheritable_attributes.each do |inheritable_attribute|
    instance_var = "@#{inheritable_attribute}"
    subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
  end
end