Class: HashWithIndifferentAccess
- Inherits:
-
Hash
show all
- Defined in:
- lib/active_support/core_ext/hash/indifferent_access.rb
Overview
this class has dubious semantics and we only have it so that people can write params instead of params
Constant Summary
ActiveSupport::CoreExtensions::Hash::Conversions::XML_FORMATTING, ActiveSupport::CoreExtensions::Hash::Conversions::XML_TYPE_NAMES
Instance Method Summary
collapse
#diff
#to_xml
#reverse_merge, #reverse_merge!
#with_indifferent_access
#assert_valid_keys, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!
Constructor Details
Returns a new instance of HashWithIndifferentAccess.
5
6
7
8
9
10
11
12
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 5
def initialize(constructor = {})
if constructor.is_a?(Hash)
super()
update(constructor)
else
super(constructor)
end
end
|
Instance Method Details
#[]=(key, value) ⇒ Object
21
22
23
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 21
def []=(key, value)
regular_writer(convert_key(key), convert_value(value))
end
|
#default(key) ⇒ Object
14
15
16
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 14
def default(key)
self[key.to_s] if key.is_a?(Symbol)
end
|
#delete(key) ⇒ Object
56
57
58
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 56
def delete(key)
super(convert_key(key))
end
|
#fetch(key, *extras) ⇒ Object
40
41
42
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 40
def fetch(key, *)
super(convert_key(key), *)
end
|
#key?(key) ⇒ Boolean
Also known as:
include?, has_key?, member?
32
33
34
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 32
def key?(key)
super(convert_key(key))
end
|
#merge(hash) ⇒ Object
52
53
54
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 52
def merge(hash)
self.dup.update(hash)
end
|
#regular_update ⇒ Object
19
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 19
alias_method :regular_update, :update
|
#regular_writer ⇒ Object
18
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 18
alias_method :regular_writer, :[]=
|
#update(other_hash) ⇒ Object
Also known as:
merge!
25
26
27
28
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 25
def update(other_hash)
other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
self
end
|
#values_at(*indices) ⇒ Object
44
45
46
|
# File 'lib/active_support/core_ext/hash/indifferent_access.rb', line 44
def values_at(*indices)
indices.collect {|key| self[convert_key(key)]}
end
|