The ramblings of Eric Seijo - Software Developer / Life Hacker

Ruby Haiku - List Specific Days of the Week

Posted by Eric Seijo Fri, 03 Jun 2011 16:16:00 GMT

Recently I had to populate a drop down menu with the dates of every Sunday for the year up to the present day.

Ruby makes this so freaking easy:

start_date = Date.new(year=2011, month=1, date=1)
end_date = Date.today
my_array = (start_date..end_date).select { |p| [0, 6].include? p.wday }

( Ruby == <3 ) 

Happy coding!