J
John Bentley
I am having the most insane time with Ruby's Hash class.
I have Array's of varied length, but whenever they are stored and then
retrieved from a Hash they become length of 1 and all the values are
somehow combined in that first cell.
Code:
aRay = ["a","b","c"]
aRay2 = ["1","2","3","4","5"]
# prints out 3
puts aRay.size
# prints out 5
puts aRay2.size
# store them
h = {"letters" => aRay, "numbers" => aRay2}
# prints out abc
puts h.values_at("letters").to_s
# prints out 12345
puts h.values_at("numbers").to_s
# retrieve the arrays
ltrArray = h.values_at("letters")
numArray = h.values_at("numbers")
# prints out abc
puts ltrArray.to_s
# prints out 12345
puts numArray.to_s
# prints out 1
puts ltrArray.size
# prints out 1
puts numArray.size
What am I doing wrong?
I have Array's of varied length, but whenever they are stored and then
retrieved from a Hash they become length of 1 and all the values are
somehow combined in that first cell.
Code:
aRay = ["a","b","c"]
aRay2 = ["1","2","3","4","5"]
# prints out 3
puts aRay.size
# prints out 5
puts aRay2.size
# store them
h = {"letters" => aRay, "numbers" => aRay2}
# prints out abc
puts h.values_at("letters").to_s
# prints out 12345
puts h.values_at("numbers").to_s
# retrieve the arrays
ltrArray = h.values_at("letters")
numArray = h.values_at("numbers")
# prints out abc
puts ltrArray.to_s
# prints out 12345
puts numArray.to_s
# prints out 1
puts ltrArray.size
# prints out 1
puts numArray.size
What am I doing wrong?