Class: HandyHash::Builder Private
- Inherits:
-
Object
- Object
- HandyHash::Builder
- Defined in:
- lib/handy_hash.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #data ⇒ Object private
-
#initialize(&block) ⇒ Builder
constructor
private
A new instance of Builder.
- #method_missing(m, *args, &block) ⇒ Object private
Constructor Details
#initialize(&block) ⇒ Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Builder.
102 103 104 105 |
# File 'lib/handy_hash.rb', line 102 def initialize(&block) @content = {} instance_eval &block if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/handy_hash.rb', line 107 def method_missing(m, *args, &block) if m =~ /\Ato_ary\Z/ || m =~ /\=$/ || args.size > 1 super else m = m.to_s if m =~ /\A_(.+)_\Z/ m = $1 end if args.empty? @content[m] = Builder.new(&block) else @content[m] = args.first end end end |
Instance Method Details
#data ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 126 127 128 129 |
# File 'lib/handy_hash.rb', line 123 def data HandyHash.new.tap do |d| @content.each do |k, v| d[k] = v.kind_of?(Builder) ? v.data : v end end end |