class

ActiveSupport::OrderedHash

v4.1.8 - Show latest stable - Superclass: Array

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 http://yaml.org/type/omap.html) to support ordered items when loading from yaml.

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

Files

  • activesupport/lib/active_support/ordered_hash.rb

1Note

Superclass of OrderedHash

mcmire ยท Apr 8, 20096 thanks

Note that in Rails 2.3, OrderedHash changed from being a subclass of Array to a subclass of Hash. This is contrary to what the documentation says above.