DEPRECATED: ActiveSupport::OrderedHash implements a hash that preserves insertion order.

oh = ActiveSupport::OrderedHash.new
oh[:a] = 1
oh[:b] = 2
oh.keys # => [:a, :b], this order is guaranteed

Also, maps the omap feature for YAML files (See yaml.org/type/omap.html) to support ordered items when loading from yaml.

ActiveSupport::OrderedHash is namespaced to prevent conflicts with other implementations.

Methods

Instance Public methods

encode_with(coder)

📝 Source code
# File activesupport/lib/active_support/ordered_hash.rb, line 29
    def encode_with(coder)
      coder.represent_seq "!omap", map { |k, v| { k => v } }
    end
🔎 See on GitHub

extractable_options?()

Returns true to make sure that this hash is extractable via Array#extract_options!

📝 Source code
# File activesupport/lib/active_support/ordered_hash.rb, line 46
    def extractable_options?
      true
    end
🔎 See on GitHub

nested_under_indifferent_access()

📝 Source code
# File activesupport/lib/active_support/ordered_hash.rb, line 41
    def nested_under_indifferent_access
      self
    end
🔎 See on GitHub

reject(*args, &block)

📝 Source code
# File activesupport/lib/active_support/ordered_hash.rb, line 37
    def reject(*args, &block)
      dup.tap { |hash| hash.reject!(*args, &block) }
    end
🔎 See on GitHub

select(*args, &block)

📝 Source code
# File activesupport/lib/active_support/ordered_hash.rb, line 33
    def select(*args, &block)
      dup.tap { |hash| hash.select!(*args, &block) }
    end
🔎 See on GitHub

to_yaml_type()

📝 Source code
# File activesupport/lib/active_support/ordered_hash.rb, line 25
    def to_yaml_type
      "!tag:yaml.org,2002:omap"
    end
🔎 See on GitHub