Skip to content

Instantly share code, notes, and snippets.

@originalhat
Last active August 29, 2015 14:20
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 originalhat/20aa7f482d2181b149df to your computer and use it in GitHub Desktop.
Save originalhat/20aa7f482d2181b149df to your computer and use it in GitHub Desktop.
Ruby Functional Pocket Reference

Functional Ruby Pocket Reference

Flatten array of hashes and assign opposing k/v pairs.

foo = [{"title"=>"candy", "amount"=>"1.00"}]
foo.map { |k, v| Hash[k["title"], k["amount"]] }.reduce({}, :merge)
# => {"candy"=>"1.00"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment