Created
August 3, 2012 04:52
-
-
Save k456/3244482 to your computer and use it in GitHub Desktop.
ruby Date#step_by_month
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Date | |
| def step_by_month(to_date, step=1) | |
| date = self | |
| op = %w(- <= >=)[step <=> 0] | |
| while date.__send__(op, to_date) | |
| yield(date) | |
| date >>= step | |
| end | |
| end | |
| end |
Author
k456
commented
Apr 24, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment