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?
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
endThat 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.
On 16 July 2014 02:00, Robert W. [email protected] wrote:
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs