From: Paul Brannan Date: 2002-02-20T00:23:51+09:00 Subject: Re: Operator overloading and multiple arguments On Tue, Feb 19, 2002 at 05:37:44AM +0900, Phil Tomson wrote: > I'm trying to overload the '<=' operator in a class in order to use it for > assignment: > > class Blah > def initialize(value=0) > @value = value > end > > def <=(new_val,time=0) > puts "time is: #{time}" > @value = new_val > end > end > > a = Blah.new > a<=5 #prints: time is 0 > a<=(8,10) #results in parse error, doesn't like the ',' > > So apparently you can't have more than one argument for an overloaded > operator (it actually kind of makes sense) - is there any way to do this? Oddly enough, a.<= 5 a.<= 8,10 works, but gives me a creepy feeling in my stomach. Using overloaded operators for alternative assignment behavior doesn't seem justifiable. Consider the case where I want to store a Blah object in a binary tree, and I expect the <= operator to be available for comparing two Blah objects; what will happen then? Paul