Module: RorHack::ClassLevelInheritableAttributes::ClassMethods

Defined in:
lib/ror_hack/active_record_hack.rb

Instance Method Summary collapse

Instance Method Details

#inheritable_attributes(*args) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/ror_hack/active_record_hack.rb', line 132

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

#inherited(subclass) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/ror_hack/active_record_hack.rb', line 143

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