Last active
August 29, 2015 13:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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