A partial hash implementation which preserves the insertion order of the keys.
Note that this class is only used on Ruby 1.8 since the built-in Hash on Ruby 1.9 automatically preserves the insertion order. However, to remain compatibility only the methods defined in this class may be used when working with OrderedHash on Ruby 1.9.
Initialize the OrderedHash object.
# File lib/kramdown/utils/ordered_hash.rb, line 25 def initialize @data = {} @order = [] end
Return the value for the key.
# File lib/kramdown/utils/ordered_hash.rb, line 36 def [](key) @data[key] end
Set the value for the key to val.
# File lib/kramdown/utils/ordered_hash.rb, line 46 def []=(key, val) @order << key if !@data.has_key?(key) @data[key] = val end
Delete the key.
# File lib/kramdown/utils/ordered_hash.rb, line 52 def delete(key) @order.delete(key) @data.delete(key) end
Iterate over the stored keys in insertion order.
# File lib/kramdown/utils/ordered_hash.rb, line 31 def each @order.each {|k| yield(k, @data[k])} end
Generated with the Darkfish Rdoc Generator 2.