Sha256: 9927c5bafe589061c31e5cb203a6dcb693d5ccab75eb1ad964f7987a1660605d
Contents?: true
Size: 1.17 KB
Versions: 14
Compression:
Stored size: 1.17 KB
Contents
module ASIR # !SLIDE # Addtional Data # # Support additional data attached to any object. module AdditionalData def _additional_data; @additional_data; end def additional_data @additional_data || EMPTY_HASH end def additional_data! @additional_data ||= { } end def additional_data= x @additional_data = x end def [] key @additional_data && @additional_data[key] end def []= key, value (@additional_data ||= { })[key] = value end def self.included target super target.extend(ModuleMethods) end module ModuleMethods # Provide a getter method that delegates to addtional_data[...]. def addr_getter *names names.each do | name | name = name.to_sym define_method(name) { | | addtional_data[name] } end end # Provide getter and setter methods that delegate to addtional_data[...]. def addr_accessor *names addr_getter *names names.each do | name | name = name.to_sym define_method(:"#{name}=") { | v | addtional_data[name] = v } end end end end # !SLIDE END end
Version data entries
14 entries across 14 versions & 1 rubygems