Module: ClassLevelInheritableAttributes::ClassMethods

Defined in:
lib/medea/inheritable_attributes.rb

Instance Method Summary collapse

Instance Method Details

#inheritable_attributes(*args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/medea/inheritable_attributes.rb', line 10

def inheritable_attributes(*args)
  #for some reason, in rails, @inheritable_attributes is set to be an empty hash here...
  #check for this strange case and account for it.
  @inheritable_attributes = [:inheritable_attributes] if @inheritable_attributes == {} ||
                                                         @inheritable_attributes == nil
  @inheritable_attributes += args
  args.each do |arg|
    class_eval %(
      class << self; attr_accessor :#{arg} end
    )
  end
  @inheritable_attributes
end

#inherited(subclass) ⇒ Object



24
25
26
27
28
29
# File 'lib/medea/inheritable_attributes.rb', line 24

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