I have two dates, example :
date1 = "4-02-2017".to_date
date2 = "4-02-2017".to_date + 29
I try to get array of date by each week with this :
(date1..date2).select{|x| Date::DAYNAMES[x.wday] == Date::DAYNAMES[date1.wday] }
Rersult :
[Sat, 04 Feb 2017,
Sat, 11 Feb 2017,
Sat, 18 Feb 2017,
Sat, 25 Feb 2017,
Sat, 04 Mar 2017]
Is there a better way to solve the case other than the way as above?