Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/9251386 to your computer and use it in GitHub Desktop.
Save Integralist/9251386 to your computer and use it in GitHub Desktop.
Passing through key and value to a reduce method block rather than just the item
# As expected the output is the key, then the value...
({ :key => :value, :foo => :bar }).reduce([]) { |pass_through, item|
puts item
}
# key
# value
# foo
# bar
# The following example is better, as we get the key AND value passed through at once...
({ :key => :value, :foo => :bar }).reduce([]) { |pass_through, (item_key, item_val) |
puts "#{item_key} / #{item_val}"
}
# key / value
# foo / bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment