From: Joel VanderWerf Date: 2002-09-12T06:58:26+09:00 Subject: Re: Multimethods (was Re: Larry Wall's comments on Ruby) Christoph wrote: > "Joel VanderWerf" wrote > .... > .... > >>Without changing Ruby internals, what about something like: >> >> >>module Physics >> >> Collide = GenericFunction.new {|actor, object, *args|} > > > Nice! ... additionally one could also explicitly specify the > number of ``dispatch-relevant arguments ? I was assuming that the gf would always dispatch on the non-* arguments, and just pass on the rest to the method that it selects, but maybe that would be the default behavior, and your suggestion below could override the default. > Collide = GenericFunction.new(2) {|actor, object, *args|} The member method is, of course, free to be more explicit about these args, as in Physics::Collide.add_method Ship, Ship do |ship, other_ship, notify| ... notify.call("You are now an ex-parrot.") end The notify argument is not required when rocks collide with each other, and so there is no need to specify it in the gf arguments. >> # >> # The generic function will dispatch on actor and object, but >> # simply pass args to the selected method. >> # >> # The distinction in the block can be detected by checking whether #arity >> # returns 3 or -3. >> # >> >>end