Module | HashAttrs |
In: |
lib/hash_attrs.rb
|
A module which adds some generators for hash based accessors.
# File lib/hash_attrs.rb, line 29 29: def hash_accessor(hash, *syms) 30: hash_reader(hash, syms) 31: hash_writer(hash, syms) 32: end
# File lib/hash_attrs.rb, line 4 4: def hash_reader(hash_sym, syms) 5: syms.each do |id| 6: id = id.to_s.downcase 7: func = Proc.new do 8: hash = instance_variable_get(hash_sym) 9: hash[id.to_sym] 10: end 11: 12: self.send(:define_method, id, func) 13: end 14: end