Detlef Reichl
1/16/2006 9:09:00 PM
Am Dienstag, den 17.01.2006, 05:55 +0900 schrieb James Edward Gray II:
> 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"]
>
i don't like redundant data...
irb(main):042:0* current = Time.now.mon
=> 1
irb(main):043:0> require "date"
=> false
irb(main):044:0> months = Date::MONTHNAMES.compact
=> ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"]
irb(main):045:0> three_month = []
=> []
irb(main):046:0> (0..2).each {|i| three_month << months[(i+current-1) %
12]}
=> 0..2
irb(main):047:0> p three_month
["January", "February", "March"]
=> nil
detlef
> James Edward Gray II
>
>