Skip to content

Instantly share code, notes, and snippets.

@orend
Created September 28, 2012 02:41
Show Gist options
  • Save orend/3797650 to your computer and use it in GitHub Desktop.
Save orend/3797650 to your computer and use it in GitHub Desktop.
each_with_object instead of inject
# replace this
%w(foo bar).inject({}) { |hsh, str| hsh[str] = str.upcase; hsh }
# with this. note that memo is second here
%w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase }
# => {'foo' => 'FOO', 'bar' => 'BAR'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment