>>>>> "Y" == Yukihiro Matsumoto <matz / zetabits.com> writes:

Y> Hmm, pretty complecated rules... Let me think.

 This is this :

pigeon% cat b.rb
#!/usr/bin/ruby
class Array
   def +(other)
      other = other.to_a unless other.kind_of? Array
      klass = Array
      if type <= other.type
         klass = other.type
      elsif other.type <= type
         klass = type
      end
      p klass
   end
end
 
class A < Array
end
class B < Array
end
class C < B
end
 
C[1] + C[1]
C[1] + B[1]
C[1] + A[1]
pigeon% 

pigeon% b.rb
C
B
Array
pigeon% 

 The advantage is that Array#+ can return a class which is not known at
 compile time.

 I don't think that it can break an old script, because with A[1] + A[1] it
 has actually an Array and with the modification it will have an A (which
 is also an Array).

 The *big* problem with this modification is that there are too many place
 where you must make the modification.

 This mean that when you make the modification, it's too easy to forget a
 modification and enter an inconsistence. This is why it's a bad idea.


Guy Decoux