Last active
August 29, 2015 14:02
-
-
Save bxt/c8fb229376050197d693 to your computer and use it in GitHub Desktop.
Building a hash in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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