From: ara.t.howard@... Date: 2006-01-17T07:08:55+09:00 Subject: Re: [newbie] this month, the next month, and the one after that On Tue, 17 Jan 2006, James Edward Gray II wrote: > On Jan 16, 2006, at 2:29 PM, David Vallner wrote: > >> Mind you, DateTime::MONTHNAMES is one-indexed, starting from January, > > We can fix that. ;) > >> so you'll have to do some index-shiftingto wrap around the end of the array >> correctly. And since there's very little I hate more than shifting array >> indices around, the exercise is left to the reader ;P > > Okay, I'll bite: > >>> current = Time.now.strftime("%B") > => "January" >>> require "date" > => true >>> months = (Date::MONTHNAMES + Date::MONTHNAMES).compact > => ["January", "February", "March", "April", "May", "June", "July", "August", > "September", "October", "November", "December", "January", "February", > "March", "April", "May", "June", "July", "August", "September", "October", > "November", "December"] >>> three_months = months[months.index(current), 3] > => ["January", "February", "March"] but irb(main):005:0> months[months.index(current), 42].size => 24 not good if the app is a mortage calculator! ;-) -a -- strong and healthy, who thinks of sickness until it strikes like lightning? preoccupied with the world, who thinks of death, until it arrives like thunder? -- milarepa