Skip to content

Instantly share code, notes, and snippets.

@bxt
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bxt/c8fb229376050197d693 to your computer and use it in GitHub Desktop.
Save bxt/c8fb229376050197d693 to your computer and use it in GitHub Desktop.
Building a hash in Ruby
# These three do the same thing:
[:type, :action].each_with_object({}) {|m,h| h[m] = order.send(m)}
[:type, :action].inject({}) {|h,m| h[m] = order.send(m); h}
Hash[[:type, :action].map {|m| [m, order.send(m)]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment