Merge pull request #53 from dandorman/hash_default_block_koans
authorMatt Darby <matt@protectedmethod.com>
Fri, 7 Oct 2011 19:56:59 +0000 (12:56 -0700)
committerMatt Darby <matt@protectedmethod.com>
Fri, 7 Oct 2011 19:56:59 +0000 (12:56 -0700)
Add koans addressing passing a block to Hash#initialize.

koans/about_hashes.rb

index 2324b04..511caa6 100644 (file)
@@ -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