Created
October 8, 2012 13:11
-
-
Save mudge/3852446 to your computer and use it in GitHub Desktop.
A tail-recursive Ruby method to split a date range into smaller month-based date ranges.
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
RubyVM::InstructionSequence.compile_option = { | |
:tailcall_optimization => true, | |
:trace_instruction => false | |
} | |
RubyVM::InstructionSequence.new(<<-RUBY).eval | |
def acc(start_date, end_date, accu) | |
if start_date >= end_date | |
accu + [end_date] | |
else | |
acc(start_date >> 1, end_date, accu + [start_date]) | |
end | |
end | |
def months(start_date, end_date) | |
acc(start_date, end_date, []) | |
end | |
RUBY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment