E
Earle Clubb
I have a hash where the values are nested arrays. I'd like to be able to
iterate over the hash and have 3 vars available in the block: key,
value[0], and value[1]. As you can see, h.each {|a,b,c|...} doesn't
work. Is there a better way to do it than the last line below? Thanks.
Earle
--------------------
irb(main):001:0> require 'pp'
=> true
irb(main):002:0> h = {0 => [[1], [2]]}
=> {0=>[[1], [2]]}
irb(main):003:0> h.each {|a, b| pp a, b}
0
[[1], [2]]
=> {0=>[[1], [2]]}
irb(main):004:0> h.each {|a, b, c| pp a, b, c}
0
[[1], [2]]
nil
=> {0=>[[1], [2]]}
irb(main):005:0> h.each {|a, b| pp a, b[0], b[1]}
0
[1]
[2]
=> {0=>[[1], [2]]}
iterate over the hash and have 3 vars available in the block: key,
value[0], and value[1]. As you can see, h.each {|a,b,c|...} doesn't
work. Is there a better way to do it than the last line below? Thanks.
Earle
--------------------
irb(main):001:0> require 'pp'
=> true
irb(main):002:0> h = {0 => [[1], [2]]}
=> {0=>[[1], [2]]}
irb(main):003:0> h.each {|a, b| pp a, b}
0
[[1], [2]]
=> {0=>[[1], [2]]}
irb(main):004:0> h.each {|a, b, c| pp a, b, c}
0
[[1], [2]]
nil
=> {0=>[[1], [2]]}
irb(main):005:0> h.each {|a, b| pp a, b[0], b[1]}
0
[1]
[2]
=> {0=>[[1], [2]]}