M
Marcin Górski
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.
Ruby 1.8.7:
irb(main):008:0> hash = { 'a' => 20, 'b' => 300, 'k' => 1 }
=> {"k"=>1, "a"=>20, "b"=>300}
irb(main):009:0> hash.each_key { |key| puts "key: #{key} #{hash[key]}" }
key: k 1
key: a 20
key: b 300
=> {"k"=>1, "a"=>20, "b"=>300}
irb(main):010:0>
In NetBeans on JRuby I wrote:
hash = { 'a' => 20, 'b' => 300, 'k' => 1 }
puts hash.each_key { |key| puts "key: #{key} #{hash[key]}" }
Output:
key: a 20
key: b 300
key: k 1
a20b300k1
I would like to have the same sequence as in JRuby. Which iterator
should I use? Thank you for help.
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.
Ruby 1.8.7:
irb(main):008:0> hash = { 'a' => 20, 'b' => 300, 'k' => 1 }
=> {"k"=>1, "a"=>20, "b"=>300}
irb(main):009:0> hash.each_key { |key| puts "key: #{key} #{hash[key]}" }
key: k 1
key: a 20
key: b 300
=> {"k"=>1, "a"=>20, "b"=>300}
irb(main):010:0>
In NetBeans on JRuby I wrote:
hash = { 'a' => 20, 'b' => 300, 'k' => 1 }
puts hash.each_key { |key| puts "key: #{key} #{hash[key]}" }
Output:
key: a 20
key: b 300
key: k 1
a20b300k1
I would like to have the same sequence as in JRuby. Which iterator
should I use? Thank you for help.