Class: ActiveSupport::OrderedHash
- Defined in:
- lib/active_support/ordered_hash.rb
Overview
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.
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
- #reject(*args, &block) ⇒ Object
- #select(*args, &block) ⇒ Object
-
#to_yaml_type ⇒ Object
:nodoc:.
Methods inherited from Hash
#as_json, #assert_valid_keys, #compact_blank, #compact_blank!, #deep_dup, #deep_merge?, #deep_stringify_keys, #deep_stringify_keys!, #deep_symbolize_keys, #deep_symbolize_keys!, #deep_transform_keys, #deep_transform_keys!, #deep_transform_values, #deep_transform_values!, #except!, #extract!, from_trusted_xml, from_xml, #present?, #reverse_merge, #reverse_merge!, #slice!, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #to_query, #to_xml, #with_indifferent_access
Methods included from DeepMergeable
#deep_merge, #deep_merge!, #deep_merge?
Instance Method Details
#encode_with(coder) ⇒ Object
29 30 31 |
# File 'lib/active_support/ordered_hash.rb', line 29 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!
46 47 48 |
# File 'lib/active_support/ordered_hash.rb', line 46 def true end |
#nested_under_indifferent_access ⇒ Object
41 42 43 |
# File 'lib/active_support/ordered_hash.rb', line 41 def nested_under_indifferent_access self end |
#reject(*args, &block) ⇒ Object
37 38 39 |
# File 'lib/active_support/ordered_hash.rb', line 37 def reject(*args, &block) dup.tap { |hash| hash.reject!(*args, &block) } end |
#select(*args, &block) ⇒ Object
33 34 35 |
# File 'lib/active_support/ordered_hash.rb', line 33 def select(*args, &block) dup.tap { |hash| hash.select!(*args, &block) } end |
#to_yaml_type ⇒ Object
:nodoc:
25 26 27 |
# File 'lib/active_support/ordered_hash.rb', line 25 def to_yaml_type "!tag:yaml.org,2002:omap" end |