From: Trans Date: 2005-11-27T07:22:28+09:00 Subject: Re: string range membership Florian, your double dispatch is interseting. While I still have no idea if anyone has understand the #cmp solution I've proposed since no one has commented on it. A fully general solution of #cmp looks something like this: def cmp( other ) return 0 if self == other loop before, after = other.succ, self.succ return -1 if before == self return 1 if after == self end end Of course no one would never use this becuase 'other' may not be an actual member and thus never hit on ==. So the only way to ensure member comparsion in a fully general way is to have the Range on hand --hence your double dispatch. A generalized solution would then be: def cmp( other, range ) return 0 if self == other arr = range.to_a arr.index( self ) <=> arr.index( other ) end But this is silly since Range can do this itself, no need to double dispatch --if #cmp is not defined on the object, Range can always expand into an array and compare indexes itself. But there's still the rick of infinite expansions. Likewise I think the double dispatching within an #element? method is in the same league. If a #cmp can't be defined and used to determine membership neither will an #element? method be able to, so Range then must resort to 'to_a.include?' Range is better off depending on a comparision method just for it to ensure compatibility with #succ --which also ensures determination of memebership with the methods we already have #member? and #include? --Then they would do exaclty what the documentation says they're supposed to do, which they actually DO NOT do at the moment. T.