Merge pull request #52 from dandorman/hash_fetch_koan
[ruby_koans.git] / koans / about_hashes.rb
index 7662488..511e3c1 100644 (file)
@@ -89,4 +89,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