Skip to content

Commit

Permalink
Add koan addressing Hash#fetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
dandorman committed Sep 8, 2011
1 parent 58565c8 commit 7c34268
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions koans/about_hashes.rb
Expand Up @@ -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"
Expand Down

0 comments on commit 7c34268

Please sign in to comment.