| Class | YAML::Pairs |
| In: |
lib/yaml/types.rb
|
| Parent: | ::Array |
Builtin collection: !pairs
# File lib/yaml/types.rb, line 155
155: def self.[]( *vals )
156: p = Pairs.new
157: 0.step( vals.length - 1, 2 ) { |i|
158: p[vals[i]] = vals[i+1]
159: }
160: p
161: end
# File lib/yaml/types.rb, line 169
169: def has_key?( k )
170: self.assoc( k ) ? true : false
171: end
# File lib/yaml/types.rb, line 175
175: def to_yaml( opts = {} )
176: YAML::quick_emit( self, opts ) do |out|
177: out.seq( taguri, to_yaml_style ) do |seq|
178: self.each do |v|
179: seq.add( Hash[ *v ] )
180: end
181: end
182: end
183: end
# File lib/yaml/types.rb, line 141
141: def yaml_initialize( tag, val )
142: if Array === val
143: val.each do |v|
144: if Hash === v
145: concat( v.to_a ) # Convert the map to a sequence
146: else
147: raise YAML::Error, "Invalid !pairs entry: " + val.inspect
148: end
149: end
150: else
151: raise YAML::Error, "Invalid !pairs: " + val.inspect
152: end
153: self
154: end