| Class | HashWithIndifferentAccess |
| In: |
activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
|
| Parent: | Hash |
This class has dubious semantics and we only have it so that people can write params[:key] instead of params[‘key’]
| []= | -> | regular_writer |
# File activesupport/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
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 25 def []=(key, value) regular_writer(convert_key(key), convert_value(value)) end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 73 def convert_key(key) key.kind_of?(Symbol) ? key.to_s : key end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 77 def convert_value(value) case value when Hash value.with_indifferent_access when Array value.collect { |e| e.is_a?(Hash) ? e.with_indifferent_access : e } else value end end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 14 def default(key = nil) if key.is_a?(Symbol) && include?(key = key.to_s) self[key] else super end end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 60 def delete(key) super(convert_key(key)) end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 52 def dup HashWithIndifferentAccess.new(self) end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 44 def fetch(key, *extras) super(convert_key(key), *extras) end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 36 def key?(key) super(convert_key(key)) end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 56 def merge(hash) self.dup.update(hash) end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 64 def stringify_keys!; self end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 65 def symbolize_keys!; self end
Convert to a Hash with String keys.
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 68 def to_hash Hash.new(default).merge(self) end
# File activesupport/lib/active_support/core_ext/hash/indifferent_access.rb, line 29 def update(other_hash) other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } self end