提交 09965710 编写于 作者: Y Yves Senn

Merge pull request #11327 from schuetzm/hash-with-indifferent-access-select

Make HashWithIndifferentAccess#select always return the hash.
* Make `HashWithIndifferentAccess#select` always return the hash, even when
`Hash#select!` returns `nil`, to allow further chaining.
*Marc Schütz*
* Remove deprecated `String#encoding_aware?` core extensions (`core_ext/string/encoding`).
*Arun Agrawal*
......
......@@ -228,7 +228,7 @@ def deep_symbolize_keys; to_hash.deep_symbolize_keys! end
def to_options!; self end
def select(*args, &block)
dup.select!(*args, &block)
dup.tap {|hash| hash.select!(*args, &block)}
end
# Convert to a regular hash with string keys.
......
......@@ -487,6 +487,12 @@ def test_indifferent_select
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
end
def test_indifferent_select_returns_a_hash_when_unchanged
hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select {|k,v| true}
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
end
def test_indifferent_select_bang
indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings)
indifferent_strings.select! {|k,v| v == 1}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册