From: David Alan Black Date: 2001-11-29T22:10:00+09:00 Subject: [ruby-talk:26888] Re: overload possible? Hello -- On Thu, 29 Nov 2001, Rich Kilmer wrote: > excellent idea...how about this refactoring... > > module Overload > def overload(args, *types) > return if args.length != types.length > args.each_index {|i| return if args[i].type.to_s != types[i].to_s} You could pass around classes instead of symbols (unless there a drawback to that I'm not seeing), in which case the above could be: args.each_index {|i| return if args[i].type != types[i]} and then: > if __FILE__ == $0 > class Fred > include Overload > def hello(*args) > overload(args, :Fixnum, :String, :Float) do overload(args, Fixnum, String, Float) do .... etc. Also: > raise TypeError, > "Invalid Signature: #{args.collect {|a| a.type.to_s}.join(', ')}" will work OK without the to_s. Hmmmm.... I'm beginning to see what Robert F. means about a form of #map where you send it a method name: def overload(args,*types) return unless args.map(:type) == types ... would certainly be concise. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav