Loop through years + months

Viewed 1959

I am trying to loop through years and months. If @user.created_at is November 2015, then I'd like to get this output:

November 2015
December 2015
January 2016
February 2016
March 2016

I tried the following:

Hash[(@user.created_at.month..Date.today.month).map { |month| [ month, 0 ] }].merge(...)

But the above code returns

stack level too deep

because it loops 11..3. How can I figure out this issue?

6 Answers
Related