Errors with size on hash value
I have some critical error with the hash's size function. This is acting irationnal.
Here is my hash :
"questionnaires"=>{"1"=>{"6"=>"8", "7"=>"12", "5"=>"19"}}
@questions=evt["questionnaires"]["1"] # not really "1", that's an id but don't matter here
@questions.each do |(key,question)| # should be "6"=>"8", then "7"=>"12", ect .开发者_Python百科..
temp = question.size
And results are 1 , 2 , 2. So it is bugging, i am testing with size cause sometimes i get an array like this :
so, i don't know why
"6"=>"8".size == 1, "7"=>"12".size == 2 and "5"=>"19".size == 2.
And with this array
"questionnaires"=>{"3"=>{"8"=>{"16"=>"16", "18"=>"18"}}}
results are correct. Size = 2, like expected.
Any ideas ?
When you have (key,question)
parameters like you do, they get filled in parallel assignment as it iterates through the hash. So, for example, the first iteration key
is "6" and question
is "8". The second iteration, key
is "7" and question
is "12".
And you are asking question.size
. But since question
is just a String, question.size
returns the length of the string. The first iteration through, the question id "8" is 1 character long. The second iteration, the question id "12" is 2 characters long. That's where the numbers you are getting are coming from.
精彩评论