Skip to content

Commit

Permalink
Add koans addressing passing a block to Hash#initialize.
Browse files Browse the repository at this point in the history
  • Loading branch information
dandorman committed Sep 8, 2011
1 parent 58565c8 commit 6acc65a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions koans/about_hashes.rb
Expand Up @@ -77,4 +77,28 @@ def test_default_value
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

0 comments on commit 6acc65a

Please sign in to comment.