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.28 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.27 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.26 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.25 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.24 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.23 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.22 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.21 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.20 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.19 shell/lib/shell/ClassLevelInheritableAttributes.rb
sct-0.1.18 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.17 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.16 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.15 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.14 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.13 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.12 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.11 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.10 lib/sct/ClassLevelInheritableAttributes.rb
sct-0.1.9 lib/sct/ClassLevelInheritableAttributes.rb