Sha256: 85c4fa0ecba912dc9cc1744a78818eec00c8fdee826b5455f96f4bab481ec9c1
Contents?: true
Size: 1.12 KB
Versions: 5
Compression:
Stored size: 1.12 KB
Contents
module ASIR # !SLIDE # Addtional Data # # Support additional data attached to any object. module AdditionalData 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
5 entries across 5 versions & 1 rubygems