Ruby date handling and other “nuances”

Most of the time when I don’t know a function in Ruby and try to guess it, I’m right. This rarely happens when I’m coding PHP. Coding gets a lot more efficient when you don’t have to run to the online API every time you want to use a core function.

Also date handling in Ruby is like this (of course you can make it much more twisted if you so desire):

You want to set a cookie that expires 30 days from now?

cookies[:mycookie] = {:value => ‘bruhaha!’, expires => 30.days.from_now }

You want to insert some specific date to a database (let’s say mysql / postgre):

puts 3.hours.from_now.to_s :db -> "2007-08-13 18:23:02"

and so on…


About this entry