Extending the to_s method


I'm developing an localization plugin (just for my own purposes) and I wanted to extend the to_s method for the Time class.

What I want to do: when someone does date.to_s(:short) that a localized version of the :short date is displayed. But I don't know how to accomplish this. I know have this:

class Time   def to_s(option)     print option.to_yaml     'lalo'   end end

Jepp... it prints all the the times to 'lalo' :slight_smile:

But how do I adjust this method so that only in the case of :short the return value is modified? Something like:

if option == :short {   return self.strftime("%Y %D %E") }

Or is there more to it?

Thanks in advance!


Maybe more concrete:

I have a model with an attribute called "ammount". It's a price stored in an integer (in cents). Is it possible to extend the to_s method for that attribute? So that I will show "€ 20,00" when I do: <%= ammount %>