Module: ClassLevelInheritableAttributes

Included in:
AddressStandardization::AbstractService
Defined in:
lib/address_standardization/class_level_inheritable_attributes.rb

Overview

Instance Method Summary collapse

Instance Method Details

#cattr_inheritable(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/address_standardization/class_level_inheritable_attributes.rb', line 3

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

#inherited(subclass) ⇒ Object



14
15
16
17
18
19
# File 'lib/address_standardization/class_level_inheritable_attributes.rb', line 14

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