From: Philipp Meier Date: 2002-09-13T19:03:09+09:00 Subject: Re: not grasping the method overloading/multi-dispatch thing --dc+cDN39EJAMEtIO Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 13, 2002 at 04:42:52PM +0900, Phil Tomson wrote: > Yes, but what about an example like this (This is some actual code I have= =20 > which I hesitate to show because I'm sure it's pretty smelly code, but=20 > I'm also not sure how else to do this): >=20 > class Signal > #.... > def assign_at (relTime=3D0,function=3Dnil) > #schedule an event > nextValue =3D case function > when nil > Proc.new.call > when Proc > function.call > when Signal > proc{function.to_s}.call > else #should probably be Fixnum > function > end > @eventQueue[relTime] =3D nextValue > nextValInQueue =3D @eventQueue.shift > @next_value =3D nextValInQueue if nextValInQueue > end >=20 > def assign(function=3Dnil) > if function > assign_at(0,function) > else > assign_at(0,Proc.new) > end > end >=20 > #.... > end What about the following? class Signal @function_handlers =3D { nil =3D> NilHandler.new, Proc =3D> ProcHandler.new, Signal =3D> SignalHandler.new, Object =3D> DefaultHandler.new } def assign_at(rel_Time=3D0, function=3Dnil) nextValue =3D @function_handlers[function.type].invoke(function) ... end end class SignalHandler(function) proc{function.to_s}.call end class DefaultHandler(function) function end =2E.. -billy. --=20 Meisterbohne S=F6flinger Stra=DFe 100 Tel: +49-731-399 499-0 eL=F6sungen 89077 Ulm Fax: +49-731-399 499-9 --dc+cDN39EJAMEtIO Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9gbf/fBriNoqItSYRAjTdAJ9L4RpNnptmNX+HQ4qEiQTHZDZUswCfXZRD Dj3zUFBcTiFR//T2Vgqs8t0= =OofH -----END PGP SIGNATURE----- --dc+cDN39EJAMEtIO--