Scott Rutherford

Life on and off the Rails

 

Ruby Time Functions Rock!!

February 4th, 2007

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….....

They lost my CSS

February 1st, 2007

I’m not entirely sure how this has happened, I suspect that RailsPlayground has moved to 1.2.1 (without telling anyone), but it appears that this blog no longer has styles…......

Brilliant. My apologies.

Anyway, gonna freeze to 1.1.6 for the mo, so hopefully that should fix it.

This blog used the Shay theme as a base and is powered by Mephisto