Class: ActiveSupport::OrderedHash
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Hash
|
|
Instance Chain:
self,
::Hash ,
DeepMergeable
|
|
Inherits: | Hash |
Defined in: | activesupport/lib/active_support/ordered_hash.rb |
Overview
DEPRECATED: 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.
OrderedHash
is namespaced to prevent conflicts with other implementations.
Class Method Summary
::Hash
- Inherited
.from_trusted_xml | Builds a |
.from_xml | Returns a |
Instance Attribute Summary
-
#extractable_options? ⇒ Boolean
readonly
Returns true to make sure that this hash is extractable via Array#extract_options!
::Hash
- Inherited
#extractable_options? | By default, only instances of |
#present? |
Instance Method Summary
- #encode_with(coder)
- #nested_under_indifferent_access
- #reject(*args, &block)
- #select(*args, &block)
- #to_yaml_type
::Hash
- Inherited
#assert_valid_keys | Validates all keys in a hash match |
#blank? | A hash is blank if it’s empty: |
#compact_blank! | Removes all blank values from the |
#deep_dup | Returns a deep copy of hash. |
#deep_merge | Returns a new hash with |
#deep_merge! | Same as |
#deep_stringify_keys | Returns a new hash with all keys converted to strings. |
#deep_stringify_keys! | Destructively converts all keys to strings. |
#deep_symbolize_keys | Returns a new hash with all keys converted to symbols, as long as they respond to |
#deep_symbolize_keys! | Destructively converts all keys to symbols, as long as they respond to |
#deep_transform_keys | Returns a new hash with all keys converted by the block operation. |
#deep_transform_keys! | Destructively converts all keys by using the block operation. |
#deep_transform_values | Returns a new hash with all values converted by the block operation. |
#deep_transform_values! | Destructively converts all values by using the block operation. |
#except! | Removes the given keys from hash and returns it. |
#extract! | Removes and returns the key/value pairs matching the given keys. |
#nested_under_indifferent_access | Alias for Hash#with_indifferent_access. |
#reverse_merge | Merges the caller into |
#reverse_merge! | Destructive |
#reverse_update | Alias for Hash#reverse_merge!. |
#slice! | Replaces the hash with only the given keys. |
#stringify_keys | Returns a new hash with all keys converted to strings. |
#stringify_keys! | Destructively converts all keys to strings. |
#symbolize_keys | Returns a new hash with all keys converted to symbols, as long as they respond to |
#symbolize_keys! | Destructively converts all keys to symbols, as long as they respond to |
#to_options | Alias for Hash#symbolize_keys. |
#to_options! | Alias for Hash#symbolize_keys!. |
#to_param | Alias for Hash#to_query. |
#to_query | Returns a string representation of the receiver suitable for use as a URL query string: |
#to_xml | Returns a string containing an XML representation of its receiver: |
#with_defaults | Alias for Hash#reverse_merge. |
#with_defaults! | Alias for Hash#reverse_merge!. |
#with_indifferent_access | Returns an |
#_deep_transform_keys_in_object | Support methods for deep transforming nested hashes and arrays. |
#_deep_transform_keys_in_object!, | |
#_deep_transform_values_in_object | Support methods for deep transforming nested hashes and arrays. |
#_deep_transform_values_in_object!, #as_json, | |
#compact_blank |
|
#deep_merge? |
DeepMergeable
- Included
#deep_merge | Returns a new instance with the values from |
#deep_merge! | Same as |
#deep_merge? | Returns true if |
Instance Attribute Details
#extractable_options? ⇒ Boolean
(readonly)
Returns true to make sure that this hash is extractable via Array#extract_options!
# File 'activesupport/lib/active_support/ordered_hash.rb', line 46
def true end
Instance Method Details
#encode_with(coder)
[ GitHub ]# File 'activesupport/lib/active_support/ordered_hash.rb', line 29
def encode_with(coder) coder.represent_seq "!omap", map { |k, v| { k => v } } end
#nested_under_indifferent_access
[ GitHub ]# File 'activesupport/lib/active_support/ordered_hash.rb', line 41
def nested_under_indifferent_access self end
#reject(*args, &block)
[ GitHub ]# File 'activesupport/lib/active_support/ordered_hash.rb', line 37
def reject(*args, &block) dup.tap { |hash| hash.reject!(*args, &block) } end
#select(*args, &block)
[ GitHub ]# File 'activesupport/lib/active_support/ordered_hash.rb', line 33
def select(*args, &block) dup.tap { |hash| hash.select!(*args, &block) } end
#to_yaml_type
[ GitHub ]# File 'activesupport/lib/active_support/ordered_hash.rb', line 25
def to_yaml_type "!tag:yaml.org,2002:omap" end