Skip to content

Instantly share code, notes, and snippets.

@baxter
Created May 21, 2011 17:22
Show Gist options
  • Save baxter/984701 to your computer and use it in GitHub Desktop.
Save baxter/984701 to your computer and use it in GitHub Desktop.
each_with_object
# Why does the first one work but not the second one?
(1..10).each_with_object([]) {|i, a| a << i*2 }
=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
(1..10).each_with_object([]) {|i, a| a += [i*2] }
=> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment