-
-
Save bogdanRada/a6af2a91a5118364b50c98bcd29e09e1 to your computer and use it in GitHub Desktop.
ruby Date#step_by_month
This file contains 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment