Created
April 20, 2013 16:32
-
-
Save mapfel/5426534 to your computer and use it in GitHub Desktop.
Ruby - day 2: hash to array and array to hash
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
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