Skip to content

Instantly share code, notes, and snippets.

@cwoodcox
Created September 26, 2011 22:52
Show Gist options
  • Save cwoodcox/1243669 to your computer and use it in GitHub Desktop.
Save cwoodcox/1243669 to your computer and use it in GitHub Desktop.
Enumerable#map vs Enumerable#collect
# 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