Nested Iterator

Is there a more compact way to do a nested each ?

value.each do |x|   x.data.each do |y|     puts 'x: ' + x + ' y: ' + y   end end

That is can this be reduced to one or two lines?

Jan Yo wrote in post #1152468:

Is there a more compact way to do a nested each ?

value.each do |x|   x.data.each do |y|     puts 'x: ' + x + ' y: ' + y   end end

That is can this be reduced to one or two lines?

value.each { |x| x.data.each { |y| puts 'x: ' + x + ' y: ' + y } }

There, one line...

Seriously though that is already about as compact a form as I'm aware of. What makes you think it should be condensed any further? As you can see my compacted version is already losing clarity and is harder to read, and understand it's purpose, than the original format.

Also, as I pointed out the last time you asked this question in a slightly different way, if you have Value has_many Ys through Data then you can say

value.ys.each { |y| puts 'x: ' + y.x + ' y: ' + y }

Colin

Thanks