From cb2381696029ad839ecddad08afea061d07685fb Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 9 Jul 2007 21:49:37 +0000 Subject: Added Hash#except which is the inverse of Hash#slice -- return the hash except the keys that are specified [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7172 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/hash_ext_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index cae19a9335..c2b7a7f1eb 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -277,6 +277,19 @@ class HashExtTest < Test::Unit::TestCase assert_equal expected, copy end end + + def test_except + original = { :a => 'x', :b => 'y', :c => 10 } + expected = { :a => 'x', :b => 'y' } + + # Should return a new hash with only the given keys. + assert_equal expected, original.except(:c) + assert_not_equal expected, original + + # Should replace the hash with only the given keys. + assert_equal expected, original.except!(:c) + assert_equal expected, original + end end class IWriteMyOwnXML -- cgit v1.2.3