Daniel Schierbeck
8/17/2006 7:49:00 PM
Henry Savr wrote:
> Mark Van Holstyn wrote:
>> In your example, you would be calling the method '>' on t1...
>>
>> t1.>(t2)
>>
>> You can define > in the class you would like to have your functionality
>> in.
>>
>> class Example
>> def >( other )
>> #do soem comparison
>> end
>> end
>
>
> Sorry, I see, that my initial question was not asked clearly.
> I know about the "> trick."
>
> The question actually was:
>
> I want to redefine a Time method >
>
> It's new behaviour should be like this:
>
> class Time1 < Time
> def >(other)
> case other.class.name
> when "Time"
> return self > other # but use the OLD > method definition.
> when ("NilClass")
> return true
> else
> # do what Ruby does originally in this case :
> # when one operand is Time, and other not the Time.
> end
> end
class Time
def > other
if other.nil?
true
else
(self <=> other) == 1
end
end
end
Cheers,
Daniel