class Kramdown::Utils::OrderedHash
methods defined in this class may be used when working with OrderedHash on Ruby 1.9.
automatically preserves the insertion order. However, to remain compatibility only the
Note that this class is only used on Ruby 1.8 since the built-in Hash on Ruby 1.9
A partial hash implementation which preserves the insertion order of the keys.
def ==(other) #:nodoc:
def ==(other) #:nodoc: return false unless other.kind_of?(self.class) @data == other.instance_variable_get(:@data) && @order == other.instance_variable_get(:@order) end
def [](key)
def [](key) @data[key] end
def []=(key, val)
def []=(key, val) @order << key if !@data.has_key?(key) @data[key] = val end
def delete(key)
def delete(key) @order.delete(key) @data.delete(key) end
def dup #:nodoc:
def dup #:nodoc: new_object = super new_object.instance_variable_set(:@data, @data.dup) new_object.instance_variable_set(:@order, @order.dup) new_object end
def each
def each @order.each {|k| yield(k, @data[k])} end
def has_key?(key)
def has_key?(key) @data.has_key?(key) end
def initialize
def initialize @data = {} @order = [] end
def inspect #:nodoc:
def inspect #:nodoc: "{" + map {|k,v| "#{k.inspect}=>#{v.inspect}"}.join(" ") + "}" end
def merge!(other)
def merge!(other) other.each {|k,v| self[k] = v} self end