Skip to content

Instantly share code, notes, and snippets.

@granolocks
Created April 3, 2012 16:00
Show Gist options
  • Select an option

  • Save granolocks/2293166 to your computer and use it in GitHub Desktop.

Select an option

Save granolocks/2293166 to your computer and use it in GitHub Desktop.
Transpose + Zip == ??
# Note, this is getting run from a Rails console.
# The results are a bit surprising.
t = User.last.attributes.to_a.transpose
# This returns an Array with 2 sub-arrays containing all attribute keys and values respectively
# => [["work_phone", ... ], ["12345678910", ...]]
Hash[t[0].zip(t[1])] == User.last.attributes
# => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment