Class OHash
In: lib/o_hash.rb
Parent: Hash

Methods

[]   new   yaml_load  

Included Modules

OHashMixIn

External Aliases

keys -> unordered_keys

Attributes

order  [RW] 

Public Class methods

[Source]

# File lib/o_hash.rb, line 179
  def self.[] ( *args )
    hsh = OHash.new
    if Hash === args[0]
      hsh.replace args[0]
    elsif (args.size % 2) != 0
      raise ArgumentError, "odd number of elements for Hash"
    else
      hsh[args.shift] = args.shift while args.size > 0
    end
    hsh
  end

[Source]

# File lib/o_hash.rb, line 174
  def initialize ( *a )
    @order = unordered_keys
    super
  end

[Source]

# File lib/o_hash.rb, line 193
  def self.yaml_load ( val )
    case val
    when Hash
      return OHash[val.to_a]
    when OHash
      return val
    when Array
      if val.all? { |x| x.is_a?(Hash) and x.size == 1 }
        h = OHash.new
        val.each do |x|
          k, v = x
          h[k] = v
        end
        return h
      end
    end
    raise ArgumentError, "Cannot create a OHash with `#{val}'"
  end

[Validate]