Skip to content
Browse files

Add koan addressing Hash#fetch.

  • Loading branch information...
1 parent 58565c8 commit 7c34268f848a359132874a285acc54cb704216c9 @dandorman dandorman committed Sep 8, 2011
Showing with 12 additions and 0 deletions.
  1. +12 −0 koans/about_hashes.rb
View
12 koans/about_hashes.rb
@@ -20,6 +20,18 @@ def test_accessing_hashes
assert_equal __, hash[:doesnt_exist]
end
+ def test_accessing_hashes_with_fetch
+ hash = { :one => "uno" }
+ assert_equal "uno", hash.fetch(:one)
+ assert_raise(___) do
+ hash.fetch(:doesnt_exist)
+ end
+
+ # THINK ABOUT IT:
+ #
+ # Why might you want to use #fetch instead of #[] when accessing hash keys?
+ end
+
def test_changing_hashes
hash = { :one => "uno", :two => "dos" }
hash[:one] = "eins"

0 comments on commit 7c34268

Please sign in to comment.
Something went wrong with that request. Please try again.