On Mon, 26 Feb 2001, Yukihiro Matsumoto wrote:
> In message "[ruby-talk:11459] Re: Time without seconds (updated/fixed)"
>     on 01/02/25, ts <decoux / moulon.inra.fr> writes:
> |Y>   class B<Array; end
> |Y>   a = A[1] + B[2]
> |Y> What do you expect?  A? B? Array?
> Hmm, pretty complecated rules... Let me think.

It seemed to me that Guy expects the class of the result to be the
"smallest" class c for which c >= self.type and c >= other.type ... this
is usually called a maximum (when used with numbers). So this is why I
call it "max" in the following example (even though the result may be a
third class... hmmm; maybe should name it: deepest_common_superclass
instead).

class Class
	def superclass_list
		a=[c=self]
		while c!=Object; c=c.superclass; a<<c; end
		a
	end
	def max(other)
		a1= self.superclass_list
		a2=other.superclass_list
		c=nil
		while a1.length>0 and a1[-1]==a2[-1]
			c = a1.pop; a2.pop
		end
		c
	end
end



Note that this definition of array return type conflicts with MetaRuby,
where Array emulators are not subclasses of Array... thus Array#+ would
return a plain Object (!).

matju