Sha256: 3d1cbfea37cee631a534a3dfa4b9facb6cca420d14d286c126db409fea9d420e

Contents?: true

Size: 681 Bytes

Versions: 24

Compression:

Stored size: 681 Bytes

Contents

module ModuleLevelInheritableAttributes
  def self.included(base)
    base.extend(ClassMethods)
  end
  
  module ClassMethods
    def mattr_inheritable(*args)
      @mattr_inheritable_attrs ||= [:mattr_inheritable_attrs]
      @mattr_inheritable_attrs += args
      args.each do |arg|
        module_eval %(
          class << self; attr_accessor :#{arg} end
        )
      end
      @mattr_inheritable_attrs
    end

    def inherited(subclass)
      @mattr_inheritable_attrs.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

24 entries across 24 versions & 4 rubygems

Version Path
alexvollmer-httparty-0.2.6 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.0 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.1 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.10 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.2 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.3 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.4 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.5 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.6 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.7 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.8 lib/module_level_inheritable_attributes.rb
jnunemaker-httparty-0.2.9 lib/module_level_inheritable_attributes.rb
juliocesar-httparty-0.2.6 lib/module_level_inheritable_attributes.rb
httparty-0.2.10 lib/module_level_inheritable_attributes.rb
httparty-0.2.0 lib/module_level_inheritable_attributes.rb
httparty-0.2.1 lib/module_level_inheritable_attributes.rb
httparty-0.2.4 lib/module_level_inheritable_attributes.rb
httparty-0.2.6 lib/module_level_inheritable_attributes.rb
httparty-0.2.8 lib/module_level_inheritable_attributes.rb
httparty-0.2.9 lib/module_level_inheritable_attributes.rb