YAML::Omap (Class)

In: yaml/types.rb
Parent: Array

Builtin collection: !omap

Methods

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

Public Class methods

[Source]

# File yaml/types.rb, line 73
        def self.[]( *vals )
            o = Omap.new
            0.step( vals.length - 1, 2 ) { |i|
                o[vals[i]] = vals[i+1]
            }
            o
        end

Public Instance methods

[Source]

# File yaml/types.rb, line 80
        def []( k )
            self.assoc( k ).to_a[1]
        end

[Source]

# File yaml/types.rb, line 83
        def []=( k, *rest )
            val, set = rest.reverse
            if ( tmp = self.assoc( k ) ) and not set
                tmp[1] = val
            else
                self << [ k, val ] 
            end
            val
        end

[Source]

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

[Source]

# File yaml/types.rb, line 95
        def is_complex_yaml?
            true
        end

[Source]

# File yaml/types.rb, line 98
        def to_yaml( opts = {} )
            YAML::quick_emit( self.object_id, opts ) { |out|
                out.seq( "!omap" ) { |seq|
                    self.each { |v|
                        seq.add( Hash[ *v ] )
                    }
                }
            }
        end

[Validate]