Time.to_s

I’m overriding Time.to_s to use a custom date format.
The method get’s an argument, nothing in the documentation says that it
should. How do I find out what the argument does?
Where can I find the sourcecode for the original Time.to_s?

On 7/1/07, Jonas [email protected] wrote:

I’m overriding Time.to_s to use a custom date format.
The method get’s an argument, nothing in the documentation says that it
should.
Hmm that is strange, I cannot pass any argument to Time#to_s, can you
specify your version?
Robert

Try Time#strftime
(string format time)
It is similar to the formatting found in other languages. You can
define your own method and simply use part of this internally in you
method:

def my_time_format(Time)
Time.strftim(%D%M)
…other code…
end

It is really that simple.

Hi Jonas,

the Object.to_s method should not expect an argument since it is per
default an alias for Object.name.

If you want a custom time format you should overwrite the instance
method. There are several ways to accomplish this. For example you
derive from Time:

class CustomTime < Time
def to_s
strftime ‘Simon says: Do your %d sit-ups on every %A.’
end
end

HF
Florian