### Home Classes Methods

### In Files

- lib/kramdown/utils/ordered_hash.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #delete
- #each
- #has_key?
- #merge!

### Included Modules

- Enumerable

### Class/Module Index

Quicksearch

- Kramdown
- Kramdown::Converter
- Kramdown::Converter::Base
- Kramdown::Converter::Html
- Kramdown::Converter::Kramdown
- Kramdown::Converter::Latex
- Kramdown::Converter::RemoveHtmlTags
- Kramdown::Converter::Toc
- Kramdown::Document
- Kramdown::Element
- Kramdown::Error
- Kramdown::Options
- Kramdown::Options::Boolean
- Kramdown::Parser
- Kramdown::Parser::Base
- Kramdown::Parser::GFM
- Kramdown::Parser::Html
- Kramdown::Parser::Html::Constants
- Kramdown::Parser::Html::ElementConverter
- Kramdown::Parser::Html::Parser
- Kramdown::Parser::Kramdown
- Kramdown::Parser::Markdown
- Kramdown::Utils
- Kramdown::Utils::Entities
- Kramdown::Utils::Entities::Entity
- Kramdown::Utils::Html
- Kramdown::Utils::OrderedHash
- Kramdown::Utils::Unidecoder

No matching classes.

# Kramdown::Utils::OrderedHash

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.

### Public Class Methods

new() click to toggle source

Initialize the OrderedHash object.

    # File lib/kramdown/utils/ordered_hash.rb, line 25
    def initialize
      @data =  {}
      @order = []
    end

### Public Instance Methods

[](key) click to toggle source

Return the value for the `key`.

    # File lib/kramdown/utils/ordered_hash.rb, line 36
    def [](key)
      @data[key]
    end

[]=(key, val) click to toggle source

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(key) click to toggle source

Delete the `key`.

    # File lib/kramdown/utils/ordered_hash.rb, line 52
    def delete(key)
      @order.delete(key)
      @data.delete(key)
    end

each() click to toggle source

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

has_key?(key) click to toggle source

Return `true` if the hash contains the key.

    # File lib/kramdown/utils/ordered_hash.rb, line 41
    def has_key?(key)
      @data.has_key?(key)
    end

merge!(other) click to toggle source

    # File lib/kramdown/utils/ordered_hash.rb, line 57
    def merge!(other)
      other.each {|k,v| self[k] = v}
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.