Thursday, November 08, 2007
Rails: Hash#diff
Documentation
None
Usage
The Hash#diff method is helpful for determining the difference between two hashes.
note: The receiver matches on both keys and values. If the pair is not matched it be returned. (for example: {:a => 1, :b => 3}.diff({:a=>2}) # => {:a=>1, :b=>3})
Test
None
Usage
The Hash#diff method is helpful for determining the difference between two hashes.
note: The receiver matches on both keys and values. If the pair is not matched it be returned. (for example: {:a => 1, :b => 3}.diff({:a=>2}) # => {:a=>1, :b=>3})
Test
unit_tests do
test "find the difference between two hashes" do
assert_equal({:b=>3}, {:a => 1, :b => 3}.diff({:a=>1}))
end
endLabels: activesupport, rails
Comments:
<< Home
The behavior with disjunct hashes deserves a test, too.
test "find the difference between two disjunct hashes" do
assert_equal({:a => 1, :x => 100}, {:a => 1}.diff({:x => 100}))
end
Post a Comment
test "find the difference between two disjunct hashes" do
assert_equal({:a => 1, :x => 100}, {:a => 1}.diff({:x => 100}))
end
<< Home



