Class: Class
- Inherits:
-
Object
- Object
- Class
- Defined in:
- lib/functional_support/core_ext/class/attribute_accessors.rb
Instance Method Summary collapse
- #attr_hash_accessor(*syms) ⇒ Object
- #attr_hash_reader(*syms) ⇒ Object
- #attr_hash_writer(*syms) ⇒ Object
Instance Method Details
#attr_hash_accessor(*syms) ⇒ Object
32 33 34 35 |
# File 'lib/functional_support/core_ext/class/attribute_accessors.rb', line 32 def attr_hash_accessor(*syms) attr_hash_writer *syms attr_hash_reader *syms end |
#attr_hash_reader(*syms) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/functional_support/core_ext/class/attribute_accessors.rb', line 3 def attr_hash_reader(*syms) = syms. hash_name = [:store_in].to_s if [:store_in].present? hash_name ||= "attributes" syms.each do |sym| raise NameError.new("invalid instance attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/ class_eval(" def \#{sym}\n (@\#{hash_name} ||= {})[:\#{sym}]\n end\n EOS\n end\nend\n", __FILE__, __LINE__ + 1) |
#attr_hash_writer(*syms) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/functional_support/core_ext/class/attribute_accessors.rb', line 17 def attr_hash_writer(*syms) = syms. hash_name = [:store_in].to_s if [:store_in].present? hash_name ||= "attributes" syms.each do |sym| raise NameError.new("invalid instance attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/ class_eval(" def \#{sym}=(obj)\n @\#{hash_name} ||= {}\n @\#{hash_name}[:\#{sym}] = obj\n end\n EOS\n end\nend\n", __FILE__, __LINE__ + 1) |