Skip to content

Instantly share code, notes, and snippets.

@decioferreira
Created June 8, 2012 10:39
Show Gist options
  • Save decioferreira/2894942 to your computer and use it in GitHub Desktop.
Save decioferreira/2894942 to your computer and use it in GitHub Desktop.
Enumerable#each_with_object
%w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase }
# => {'foo' => 'FOO', 'bar' => 'BAR'}
evens = (1..10).each_with_object([]) {|i, a| a << i*2 }
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment