From: Mike Austin Date: 2006-03-21T15:48:50+09:00 Subject: Re: Method overload, care to improve? Here's a working prototype: class Test #generic :foo (would generate the code below) @@foo = Object.new define_method :foo do |*args| method = args.map { |a| a.class }.join( "_" ) @@foo.send( method, *args ) end end class Test def @@foo.Fixnum_Fixnum( x, y ) return x * y end def @@foo.Fixnum_Float( x, y ) return x / y end end t = Test.new t.foo( 10, 20 ) t.foo( 10, 2.0 ) It's inefficient and all that, but I think it looks pretty nice :) Mike Trans wrote: > Thanks Andrew. > > I'm afraid I don't care for how the strongtyping lib handles > overloading with the #overload call internal to the method. It > undermines dynamic capabilities. Eg. > > def bar(*args) > overload(args, String, String) { > | s1, s2 | > ... > return > } > > overload(args, String, Integer) { > | s, i | > ... > return > } > > overload_error args > end > > It would be tricky to add another overload post defnition of the > original.