Sha256: ab429d0298add1a2be89fa5f0ceb7f7a63d8ea4a87deea40c6ed626008a184ed

Contents?: true

Size: 740 Bytes

Versions: 38

Compression:

Stored size: 740 Bytes

Contents

# taken directly from http://stackoverflow.com/a/10729812/90042
module ClassLevelInheritableAttributes
  def self.included(base)
    base.extend(ClassMethods)    
  end

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

      @inheritable_attributes
    end

    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
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
passive_record-0.4.15 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.14 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.13 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.12 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.11 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.10 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.8 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.7 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.6 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.5 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.4 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.3 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.2 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.1 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.4.0 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.3.22 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.3.21 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.3.20 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.3.19 lib/passive_record/class_inheritable_attrs.rb
passive_record-0.3.18 lib/passive_record/class_inheritable_attrs.rb