Skip to content

Instantly share code, notes, and snippets.

@mapfel
Created April 20, 2013 16:32
Show Gist options
  • Save mapfel/5426534 to your computer and use it in GitHub Desktop.
Save mapfel/5426534 to your computer and use it in GitHub Desktop.
Ruby - day 2: hash to array and array to hash
a1 = ["a", 1, "b", 2]
h1 = Hash[*a1]
puts "a1=" + a1.to_s
puts "h1=" + h1.to_s
a2 = [["a", 1], ["b", 2]]
h2 = Hash[*a1] #splat operator (*) used
puts "a2=" + a2.to_s
puts "h2=" + h2.to_s
puts h1 == h2
a1 = h1.to_a
puts "a1=" + a1.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment