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

Builtin collection: !omap

Methods

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

Public Class methods

[Source]

     # File lib/yaml/types.rb, line 102
102:         def self.[]( *vals )
103:             o = Omap.new
104:             0.step( vals.length - 1, 2 ) do |i|
105:                 o[vals[i]] = vals[i+1]
106:             end
107:             o
108:         end

Public Instance methods

[Source]

     # File lib/yaml/types.rb, line 109
109:         def []( k )
110:             self.assoc( k ).to_a[1]
111:         end

[Source]

     # File lib/yaml/types.rb, line 112
112:         def []=( k, *rest )
113:             val, set = rest.reverse
114:             if ( tmp = self.assoc( k ) ) and not set
115:                 tmp[1] = val
116:             else
117:                 self << [ k, val ] 
118:             end
119:             val
120:         end

[Source]

     # File lib/yaml/types.rb, line 121
121:         def has_key?( k )
122:             self.assoc( k ) ? true : false
123:         end

[Source]

     # File lib/yaml/types.rb, line 124
124:         def is_complex_yaml?
125:             true
126:         end

[Source]

     # File lib/yaml/types.rb, line 127
127:         def to_yaml( opts = {} )
128:             YAML::quick_emit( self.object_id, opts ) do |out|
129:                 out.seq( taguri, to_yaml_style ) do |seq|
130:                     self.each do |v|
131:                         seq.add( Hash[ *v ] )
132:                     end
133:                 end
134:             end
135:         end

[Source]

     # File lib/yaml/types.rb, line 88
 88:         def yaml_initialize( tag, val )
 89:             if Array === val
 90:                 val.each do |v|
 91:                     if Hash === v
 92:                         concat( v.to_a )                # Convert the map to a sequence
 93:                     else
 94:                         raise YAML::Error, "Invalid !omap entry: " + val.inspect
 95:                     end
 96:                 end
 97:             else
 98:                 raise YAML::Error, "Invalid !omap: " + val.inspect
 99:             end
100:             self
101:         end

[Validate]