Class YAML::Pairs
In: lib/yaml/types.rb
Parent: ::Array

Builtin collection: !pairs

Methods

[]   []   []=   has_key?   is_complex_yaml?   to_yaml   yaml_initialize  

Public Class methods

[Source]

     # File lib/yaml/types.rb, line 157
157:         def self.[]( *vals )
158:             p = Pairs.new
159:             0.step( vals.length - 1, 2 ) { |i|
160:                 p[vals[i]] = vals[i+1]
161:             }
162:             p
163:         end

Public Instance methods

[Source]

     # File lib/yaml/types.rb, line 164
164:         def []( k )
165:             self.assoc( k ).to_a
166:         end

[Source]

     # File lib/yaml/types.rb, line 167
167:         def []=( k, val )
168:             self << [ k, val ] 
169:             val
170:         end

[Source]

     # File lib/yaml/types.rb, line 171
171:         def has_key?( k )
172:             self.assoc( k ) ? true : false
173:         end

[Source]

     # File lib/yaml/types.rb, line 174
174:         def is_complex_yaml?
175:             true
176:         end

[Source]

     # File lib/yaml/types.rb, line 177
177:         def to_yaml( opts = {} )
178:             YAML::quick_emit( self.object_id, opts ) do |out|
179:                 out.seq( taguri, to_yaml_style ) do |seq|
180:                     self.each do |v|
181:                         seq.add( Hash[ *v ] )
182:                     end
183:                 end
184:             end
185:         end

[Source]

     # File lib/yaml/types.rb, line 143
143:         def yaml_initialize( tag, val )
144:             if Array === val
145:                 val.each do |v|
146:                     if Hash === v
147:                         concat( v.to_a )                # Convert the map to a sequence
148:                     else
149:                         raise YAML::Error, "Invalid !pairs entry: " + val.inspect
150:                     end
151:                 end
152:             else
153:                 raise YAML::Error, "Invalid !pairs: " + val.inspect
154:             end
155:             self
156:         end

[Validate]