mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Merge pull request #52 from dandorman/hash_fetch_koan
Add koan addressing Hash#fetch.
This commit is contained in:
@@ -20,6 +20,18 @@ class AboutHashes < EdgeCase::Koan
|
|||||||
assert_equal __, hash[:doesnt_exist]
|
assert_equal __, hash[:doesnt_exist]
|
||||||
end
|
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
|
def test_changing_hashes
|
||||||
hash = { :one => "uno", :two => "dos" }
|
hash = { :one => "uno", :two => "dos" }
|
||||||
hash[:one] = "eins"
|
hash[:one] = "eins"
|
||||||
|
|||||||
Reference in New Issue
Block a user