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 100
100:         def self.[]( *vals )
101:             o = Omap.new
102:             0.step( vals.length - 1, 2 ) do |i|
103:                 o[vals[i]] = vals[i+1]
104:             end
105:             o
106:         end

Public Instance methods

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Validate]