Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elomatreb/6c306be48e2b55b0a2badee109af76ac to your computer and use it in GitHub Desktop.
Save elomatreb/6c306be48e2b55b0a2badee109af76ac to your computer and use it in GitHub Desktop.
return hash.reduce({}) do |acc, kv|
acc[id + kv[0]] = { 'key' => kv[0], 'value' => kv[1] }
acc # You're explicitely returning acc so it used again by the next invocation of the block
end
########
return hash.each_with_object({}) do |kv, acc| # Argument order is switched
acc[id + kv[0]] = { 'key' => kv[0], 'value' => kv[1] }
# no need to explicitely return
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment