Real life use of each_cons? (... follow up)

J

Jakub

Hi there!

(following up the discussion from last year)

This method actually made my life a lot easier when fitting some data
to a table. I had tens of pictures and wanted to show them in rows -
three columns each.

data.each_cons(3) do |column|
column.each do |picture|
show picture
end
end

I was playing with indices, modulos and stuff. After refactoring with
each_cons, the code looked much cleaner.

cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,266
Latest member
DavidaAlla

Latest Threads

Top