aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorStefan Schüßler <mail@stefanschuessler.de>2019-01-29 11:49:23 +0100
committerStefan Schüßler <mail@stefanschuessler.de>2019-01-30 08:31:37 +0100
commitfc6a525341d7a287740d3e61beaccabd3e65bdc3 (patch)
tree900b3023ae291e8567ef9551b469ebedee5fa792 /activesupport/lib/active_support
parentdeac9ec430f652ddea485c92f39f7b00ebb4d4a5 (diff)
downloadrails-fc6a525341d7a287740d3e61beaccabd3e65bdc3.tar.gz
rails-fc6a525341d7a287740d3e61beaccabd3e65bdc3.tar.bz2
rails-fc6a525341d7a287740d3e61beaccabd3e65bdc3.zip
Add HashWithIndifferentAccess#assoc
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index f1af76019a..3a2b2652c4 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -164,6 +164,19 @@ module ActiveSupport
super(convert_key(key))
end
+ # Same as <tt>Hash#assoc</tt> where the key passed as argument can be
+ # either a string or a symbol:
+ #
+ # counters = ActiveSupport::HashWithIndifferentAccess.new
+ # counters[:foo] = 1
+ #
+ # counters.assoc('foo') # => ["foo", 1]
+ # counters.assoc(:foo) # => ["foo", 1]
+ # counters.assoc(:zoo) # => nil
+ def assoc(key)
+ super(convert_key(key))
+ end
+
# Same as <tt>Hash#fetch</tt> where the key passed as argument can be
# either a string or a symbol:
#