Created
September 26, 2011 22:52
-
-
Save cwoodcox/1243669 to your computer and use it in GitHub Desktop.
Enumerable#map vs Enumerable#collect
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
# Using #collect in this example makes more sense in my head, because it's kinda like Array#join | |
twitter.user_timeline('cwoodcox').tweets.collect do |tweet| | |
"#{tweet.username}: \" #{tweet.text}\"" | |
end | |
# Using #map in this context makes more sense in my head, since we're operating on every element | |
my_stats_array.map do |stat| | |
stat * 2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment