1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00
httparty/lib/module_level_inheritable_attributes.rb

25 lines
681 B
Ruby

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