How can I loop through each of the days of a given week in Ruby?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-05-18T18:45:05Z Indexed on 2010/05/18 18:50 UTC
Read the original article Hit count: 195

Filed under:
|
|

I am defining monday and friday using the following:

@monday = Date.today.at_beginning_of_week

@friday = 5.days.since(@monday)

But I actually need, for any given day, to loop through Monday, Tuesday, Wednesday and take that date and put the output into a column.

<th>Monday</th>
<th>Tuesday</th>
etcetera

A given row, for example, would be:

<tr><td>value(monday)</td><td>value(tuesday)</td><td>value(wednesday)</td></tr>

This is where value is a method that takes args date.

What's the cleanest way to do this?

Thanks.

© Stack Overflow or respective owner

Related posts about loops

Related posts about dates