aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_hash.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-13 08:06:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-13 08:06:00 +0000
commitbbd58fa2b956a33c035dbddc83e9efbe07ee7276 (patch)
tree6465e05d16a1f6deb7ff51230227e4b75d99d4d4 /test/ruby/test_hash.rb
parent5b3b8554c9f851a958c03fc707bd69e6ad6c5c13 (diff)
downloadruby-bbd58fa2b956a33c035dbddc83e9efbe07ee7276.tar.gz
hash.c: add compact and compact! methods
* hash.c (rb_hash_compact, rb_hash_compact_bang): Removes nil values from the original hash, to port Active Support behavior. [Feature #11818] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_hash.rb')
-rw-r--r--test/ruby/test_hash.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index edc0eeebee..7720b6098e 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -354,6 +354,14 @@ class TestHash < Test::Unit::TestCase
assert_equal({1=>2,3=>4,5=>6}, h.keep_if{true})
end
+ def test_compact
+ h = @cls[a: 1, b: nil, c: false, d: true, e: nil]
+ assert_equal({a: 1, c: false, d: true}, h.compact)
+ assert_equal({a: 1, b: nil, c: false, d: true, e: nil}, h)
+ h.compact!
+ assert_equal({a: 1, c: false, d: true}, h)
+ end
+
def test_dup
for taint in [ false, true ]
for frozen in [ false, true ]