From: Dan Dorman Date: Thu, 8 Sep 2011 15:48:41 +0000 (-0600) Subject: Add koans addressing passing a block to Hash#initialize. X-Git-Url: https://git.eng.unimelb.edu.au/public?p=ruby_koans.git;a=commitdiff_plain;h=6acc65ac9294e89a35b70e8ee0efc31594cee551 Add koans addressing passing a block to Hash#initialize. --- diff --git a/koans/about_hashes.rb b/koans/about_hashes.rb index 2324b04..511caa6 100644 --- a/koans/about_hashes.rb +++ b/koans/about_hashes.rb @@ -77,4 +77,28 @@ class AboutHashes < EdgeCase::Koan assert_equal __, hash2[:one] assert_equal __, hash2[:two] end + + def test_default_value_is_the_same_object + hash = Hash.new([]) + + hash[:one] << "uno" + hash[:two] << "dos" + + assert_equal __, hash[:one] + assert_equal __, hash[:two] + assert_equal __, hash[:three] + + assert_equal __, hash[:one].object_id == hash[:two].object_id + end + + def test_default_value_with_block + hash = Hash.new {|hash, key| hash[key] = [] } + + hash[:one] << "uno" + hash[:two] << "dos" + + assert_equal __, hash[:one] + assert_equal __, hash[:two] + assert_equal __, hash[:three] + end end