Class: HashWithIndifferentAccess
- Inherits:
-
Hash
- Object
- Hash
- HashWithIndifferentAccess
show all
- Defined in:
- lib/fleck/hash_with_indifferent_access.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Hash
#to_hash_with_indifferent_access
Constructor Details
Returns a new instance of HashWithIndifferentAccess.
3
4
5
6
|
# File 'lib/fleck/hash_with_indifferent_access.rb', line 3
def initialize(original)
super(nil)
copy_from(original)
end
|
Class Method Details
.convert_value(value) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/fleck/hash_with_indifferent_access.rb', line 24
def self.convert_value(value)
if value.is_a?(Hash)
value.to_hash_with_indifferent_access
elsif value.is_a?(Array)
value.map!{|item| item.is_a?(Hash) || item.is_a?(Array) ? HashWithIndifferentAccess.convert_value(item) : item }
else
value
end
end
|
Instance Method Details
#[](key) ⇒ Object
12
13
14
|
# File 'lib/fleck/hash_with_indifferent_access.rb', line 12
def [](key)
super(key.to_s)
end
|
#[]=(key, value) ⇒ Object
8
9
10
|
# File 'lib/fleck/hash_with_indifferent_access.rb', line 8
def []=(key, value)
super(key.to_s, self.class.convert_value(value))
end
|
#delete(key) ⇒ Object
20
21
22
|
# File 'lib/fleck/hash_with_indifferent_access.rb', line 20
def delete(key)
super(key.to_s)
end
|
#fetch(key, *extras) ⇒ Object
16
17
18
|
# File 'lib/fleck/hash_with_indifferent_access.rb', line 16
def fetch(key, *)
super(key.to_s, *)
end
|