From: Wilson Bilkovich Date: 2006-10-24T10:48:07+09:00 Subject: Re: Override Time#to_s -- how? On 10/23/06, Ben Winekur wrote: > Hey everyone, > > I'd like to override the Time#to_s function to parse Time objects a > specific way -- how can I do this from within my script? (Without > modifying the Time class itself) > > Thanks, > Ben > What do you mean by 'without modifying the Time class itself'? Isn't that precisely what you want to do? All classes are 'open' in Ruby, so you can simply do: class Time def to_s "blah" end end If you need access to the original method as well, you can do this: class Time alias_method :original_to_s, :to_s def to_s "The old to_s method would have said: " + self.original_to_s end end