I've a problem with generic methods.

 With this example, what do you expect for the second call
 (i.e. a.toto(B::C.new)).

pigeon% cat b.rb
#!./ruby
class B
   class C
   end
end
module D
   def toto(B::C b, String d = "")
      puts "B::C #{b} -- String #{d}"
   end
end
 
class A
   include D
   def toto(B::C b, Array c = [12, 24])
      puts "B::C #{b} -- Array #{c.join ' '}"
   end
   def toto(Array b, B::C c = B::C.new)
      puts "Array #{b.join ' '} -- B::C #{c}"
   end
   def toto(Array b, Array c = [3, 4])
      puts "Array #{b.join ' '} -- Array #{c.join ' '}"
   end
end
 
a = A.new
 
a.toto(B::C.new, "toto")
a.toto(B::C.new)
a.toto([1, 2])
pigeon% b.rb
B::C #<B::C:0x40198910> -- String toto
B::C #<B::C:0x401988e8> -- Array 12 24
./b.rb:29: ambiguous call for toto ([Array, B::C] -- [Array, Array]) (RuntimeError)
pigeon% 

 it must give an error or not ?


Guy Decoux