git://git.eng.unimelb.edu.au
/
ruby_koans.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
(from parent 1:
2871422
)
Merge pull request #52 from dandorman/hash_fetch_koan
author
Matt Darby
<matt@protectedmethod.com>
Fri, 7 Oct 2011 19:58:45 +0000
(12:58 -0700)
committer
Matt Darby
<matt@protectedmethod.com>
Fri, 7 Oct 2011 19:58:45 +0000
(12:58 -0700)
Add koan addressing Hash#fetch.
koans/about_hashes.rb
patch
|
blob
|
history
diff --git
a/koans/about_hashes.rb
b/koans/about_hashes.rb
index
511caa6
..
511e3c1
100644
(file)
--- a/
koans/about_hashes.rb
+++ b/
koans/about_hashes.rb
@@
-20,6
+20,18
@@
class AboutHashes < EdgeCase::Koan
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"