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?
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
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.
···
On Jul 1, 2007, at 5:40 AM, Florian Aßmann wrote:
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