Class: ActiveSupport::OrderedHash
- Defined in:
- activesupport/lib/active_support/ordered_hash.rb
Overview
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.
Instance Method Summary collapse
- #encode_with(coder) ⇒ Object
-
#extractable_options? ⇒ Boolean
Returns true to make sure that this hash is extractable via
Array#extract_options!
. - #nested_under_indifferent_access ⇒ Object
- #to_yaml_type ⇒ Object
Methods inherited from Hash
#as_json, #assert_valid_keys, #deep_dup, #deep_merge, #deep_merge!, #deep_stringify_keys, #deep_stringify_keys!, #deep_symbolize_keys, #deep_symbolize_keys!, #deep_transform_keys, #deep_transform_keys!, #encode_json, #except, #except!, #extract!, from_trusted_xml, from_xml, #reverse_merge, #reverse_merge!, #slice, #slice!, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #to_param, #to_xml, #transform_keys, #transform_keys!, #with_indifferent_access
Instance Method Details
#encode_with(coder) ⇒ Object
27 28 29 |
# File 'activesupport/lib/active_support/ordered_hash.rb', line 27 def encode_with(coder) coder.represent_seq '!omap', map { |k,v| { k => v } } end |
#extractable_options? ⇒ Boolean
Returns true to make sure that this hash is extractable via Array#extract_options!
36 37 38 |
# File 'activesupport/lib/active_support/ordered_hash.rb', line 36 def true end |
#nested_under_indifferent_access ⇒ Object
31 32 33 |
# File 'activesupport/lib/active_support/ordered_hash.rb', line 31 def nested_under_indifferent_access self end |
#to_yaml_type ⇒ Object
23 24 25 |
# File 'activesupport/lib/active_support/ordered_hash.rb', line 23 def to_yaml_type "!tag:yaml.org,2002:omap" end |