Skip to content

Instantly share code, notes, and snippets.

@gerhard
Created January 2, 2009 14:06
Show Gist options
  • Save gerhard/42537 to your computer and use it in GitHub Desktop.
Save gerhard/42537 to your computer and use it in GitHub Desktop.
# each approach
locations = []
stocks.each {|stock| locations << stock.location}
return locations
# refactored with inject
stocks.inject([]) {|locations, stock| locations << stock.location}
# GO RUDY! http://gist.github.com/42552
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment