From: Robert Klemme Date: 2009-05-25T02:00:08+09:00 Subject: Re: Workarounds for replacing self On 24.05.2009 18:07, Jp Hastings-spital wrote: > There were a few other methods I needed - have a look: > http://gist.github.com/116293 > > I realise its potentially overkill making a whole new class for this, > but some of the scripts I'm now using this in have boths times and ETAs, > and a quick 'is_a?' allows me to distinguish them easily. > Let me know if you think you can improve it! Not much change - you don't need all the "selfs": class ETA < Time # Takes a number of seconds until the event def self.relative(seconds) at Time.now.to_i + seconds end # Requires http://gist.github.com/116290 def to_s roughly end # Gives a full textual representation of the time expected time of arrival (Time.rfc2822) def eta rfc2822 end # Has the eta passed? def arrived? self < Time.now end end And you can directly compare Time and ETA objects. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/