diff options
author | Xavier Noria <fxn@hashref.com> | 2012-07-21 08:04:37 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2012-07-21 08:05:53 +0200 |
commit | a37b90caf4262fd0ef4141e1e15cca3745af6912 (patch) | |
tree | 482e5dbcbd625ebc8ab9e9a227c4cfb126019854 /activesupport | |
parent | 089371ac23f35550676e6c5ac99e789a97101475 (diff) | |
download | rails-a37b90caf4262fd0ef4141e1e15cca3745af6912.tar.gz rails-a37b90caf4262fd0ef4141e1e15cca3745af6912.tar.bz2 rails-a37b90caf4262fd0ef4141e1e15cca3745af6912.zip |
Hash#fetch(fetch) is not the same as doing hash[key]
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 674e4acfd6..9e7cb76307 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -93,7 +93,17 @@ module ActiveSupport alias_method :has_key?, :key? alias_method :member?, :key? - # Fetches the value for the specified key, same as doing hash[key] + # Same as <tt>Hash#fetch</tt> where the key passed as argument can be + # either a string or a symbol: + # + # counters = HashWithIndifferentAccess.new + # counters[:foo] = 1 + # + # counters.fetch("foo") # => 1 + # counters.fetch(:bar, 0) # => 0 + # counters.fetch(:bar) {|key| 0} # => 0 + # counters.fetch(:zoo) # => KeyError: key not found: "zoo" + # def fetch(key, *extras) super(convert_key(key), *extras) end |