Ruby Ruby Collections Ruby Hashes Hash Methods

Eric Wheeler
Eric Wheeler
2,587 Points

Why a syntax error?

final_item = {grocery_item.merge({ "calories" => 100 })}

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
calories = { "calories" => 100 }

final_item = {grocery_item.merge({ "calories" => 100 })}

1 Answer

Grace Kelly
Grace Kelly
33,980 Points

Hi Eric, you've got the right idea however we write use a merge method like so:

merged_item = merge_this.merge(with_this)

You can read more about the merge method here: http://devdocs.io/ruby~2.5/hash#method-i-merge

Hope that helps!!