Trouble advancing date in iterator

P

Peter Marks

I am trying to assemble an array of month names called
"names_of_months_paid":

0 first_month_paid = client.first_month_paid
1 names_of_months_paid = []
2 number_of_months_paid.times do
3 names_of_months_paid << first_month_paid.strftime("%B")
4 first_month_paid >> (1)
5 end

For each payment ("number_of_months_paid"), I need to store the name of
the month, then store the name of the next month starting from
"first_month_paid". I seem to be having trouble advancing the month of
"first_month_paid" on line 4 as I am left with an array of first month
names. How might I get this to work?
 
R

Robert Dober

I am trying to assemble an array of month names called
"names_of_months_paid":

0 first_month_paid = client.first_month_paid
1 names_of_months_paid = []
2 number_of_months_paid.times do
3 names_of_months_paid << first_month_paid.strftime("%B")
4 first_month_paid >> (1)
5 end

For each payment ("number_of_months_paid"), I need to store the name of
the month, then store the name of the next month starting from
"first_month_paid". I seem to be having trouble advancing the month of
"first_month_paid" on line 4 as I am left with an array of first month
names. How might I get this to work?
irb(main):020:0> t=Time::now
=> Wed Nov 28 11:50:38 +0100 2007
irb(main):021:0> t.month
=> 11
irb(main):022:0> Date::MONTHNAMES[t.month]
=> "November"
irb(main):023:0> m = 12
=> 12
irb(main):024:0> Date::MONTHNAMES[(m % 12 ).succ]
=> "January"
irb(main):025:0> m = 1
=> 1
irb(main):026:0> Date::MONTHNAMES[(m % 12 ).succ]
=> "February"

HTH
Robert
 
P

Peter Marks

Thanks for your suggestions Robert. Looks like this is all I needed to
do:

4 first_month_paid = first_month_paid >> (1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top