I haven’t had much cause to play with the Time module in Ruby until today. I have used Time.now quite a bit, but not too much more than that. However, today I had to find the last 6 months names to label a graph and in a short period of time I had come up with this:
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] labels = [] 0.upto(5) do |x| labels.unshift(months[Time.now.months_ago(x).month-1]) end
Which I think is pretty neat, especially remembering what a pain it was in Perl last time I had to do it……..











