Hi,
I use NetBeans as IDE for Ruby. I tested my script on JRuby and got
result I expected. The problem concern Hash and each_key iterator. I
have diffrent result on Ruby 1.8.7.
Hi,
I use NetBeans as IDE for Ruby. I tested my script on JRuby and got
result I expected. The problem concern Hash and each_key iterator. I
have diffrent result on Ruby 1.8.7.
(snip)
I would like to have the same sequence as in JRuby. Which iterator
should I use? Thank you for help.
I don’t think you’re going to get it. In 1.8.7 hashes are by definition
unordered and the actual order is implementation-specific.
I don’t think you’re going to get it. In 1.8.7 hashes are by definition
unordered and the actual order is implementation-specific.
Well I found information on JRuby 1.2 page:
“A 1.8.6 compatible Ruby interpreter written in 100% pure Java.”
I think that Ruby 1.8.7 and 1.8.6 shouldn’t differ very much.
2009/7/24 Marcin G�rski [email protected]:
This means that you can’t rely on a particular order, so even though
JRuby enumerates this particular hash in that order, and 1.8.7
enumerates in a different order, they both are compatible with the
documented behavior.
Thank you for your answers. I solved my problem without relying on
each_key using additional arrays, uniq and has_key?.
I don’t think you’re going to get it. In 1.8.7 hashes are by definition
unordered and the actual order is implementation-specific.
Well I found information on JRuby 1.2 page:
“A 1.8.6 compatible Ruby interpreter written in 100% pure Java.”
I think that Ruby 1.8.7 and 1.8.6 shouldn’t differ very much.
Well they differ, although not in this regard. BUT
The point is than in Ruby < 1.9, there is no specified guarantee about
the order in which hashes enumerate their elements.
This means that you can’t rely on a particular order, so even though
JRuby enumerates this particular hash in that order, and 1.8.7
enumerates in a different order, they both are compatible with the
documented behavior.