Help with Class Extension Debugging Exercises(#my_merge)


I need some help with the the #my_merge method. I’m unable to pass the last two tests and I’m not really sure what direction I’m supposed to be going with this. Some detailed guidance would be greatly appreciated. Thanks!

Here’s what my code looks like:

def my_merge(hash2, &prc)
new_hash = self
if prc
hash2.each do |k2, v2|
new_hash[k2] =, new_hash[k2], v2)
hash2.each do |k2, v2|
new_hash[k2] = v2

Not sure why it collapsed my indenting, but it’s there in the actual code.

For the last spec, you need to evaluate if new_hash[k2]!=nil before calling the proc.
If new_hash[k2] is nill, you would merely do new_hash[k2] = v2
For the second last spec, I am not sure if proc call is treated similar to yield. I defined my method without a proc and used yield if block_given?
Hope this helps.

1 Like