Sha256: 265db14240cd3c9cbb9a698712fdd5348018addd0e38c3dbc38c7ffa6587b953

Contents?: true

Size: 675 Bytes

Versions: 25

Compression:

Stored size: 675 Bytes

Contents

module ClassLevelInheritableAttributes
  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods
    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

    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

25 entries across 25 versions & 1 rubygems

Version Path
sct-0.1.8 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.7 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.6 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.5 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.4 lib/sct/ClassLevelInheritableAttributes.rb