diff options
author | yui-knk <spiketeika@gmail.com> | 2016-10-26 11:18:10 +0900 |
---|---|---|
committer | yui-knk <spiketeika@gmail.com> | 2016-10-26 11:18:10 +0900 |
commit | c51a9b975f152ac6ff64514320fd33ae2c2c442f (patch) | |
tree | 16e83cfa300bd836f2c061fc421d1e91bd172908 | |
parent | c0e656fe40afbec5fe5851074515273303a942e7 (diff) | |
download | rails-c51a9b975f152ac6ff64514320fd33ae2c2c442f.tar.gz rails-c51a9b975f152ac6ff64514320fd33ae2c2c442f.tar.bz2 rails-c51a9b975f152ac6ff64514320fd33ae2c2c442f.zip |
Ensure `#transform_values` of HWIDA to return HWIDA
On Ruby 2.4, naitive `Hash#transform_values` is implemented.
`Hash#transform_values` uses an instance of Hash (`rb_hash_new`) to
collect returned values of a block.
For ensuring `#transform_values` of HWIDA to return HWIDA, we should
define `#transform_values` on HWIDA.
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 5 |
1 files changed, 5 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 7ecc5c19bd..d3bb5496bf 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -273,6 +273,11 @@ module ActiveSupport dup.tap { |hash| hash.reject!(*args, &block) } end + def transform_values(*args, &block) + return to_enum(:transform_values) unless block_given? + dup.tap { |hash| hash.transform_values!(*args, &block) } + end + # Convert to a regular hash with string keys. def to_hash _new_hash = Hash.new |