From: Konrad Meyer Date: 2007-08-10T03:46:43+09:00 Subject: Re: define_method with default parameters --nextPart12916457.GPyYVRSguV Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Thursday 09 August 2007 11:38:06 am Tom Werner wrote: > Gordon Thiesfeld wrote: > > On Aug 9, 11:40 am, Emmanuel Oga > > wrote: > > =20 > >> how can i use define_method to assign default parameters? > >> > >> =20 > > > > Not sure if this is the most elegant way, but: > > > > define_method(:method_name) do |*args| > > parameter, parameter2 =3D *args > > parameter2 ||=3D 'default' > > puts parameter > > puts parameter2 > > end > > > > > > =20 >=20 >=20 > Has the addition of block argument defaults to the language been=20 > considered? There are a number of places (especially in define_method,=20 > Proc.new, and lambda) where it would come in handy. The syntax would of=20 > course be: >=20 > def foo > yield 'from method' > end >=20 > foo do |x, y =3D 'from default'| > puts x > puts y > end >=20 > Which would output: >=20 > from method > from default >=20 > I've seen this come up enough that its addition would seem welcome. Are=20 > there arguments against it? >=20 > Tom I believe this has come up *lots*. IIRC, the current response is that such block defaults are not possible with the lexical parser / grammar ruby currently uses. =2D-=20 Konrad Meyer http://konrad.sobertillnoon.com/ --nextPart12916457.GPyYVRSguV Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBGu2EXCHB0oCiR2cwRAqn4AKDI+hbQThTHGWVTtQ2PumZu1uQEaQCcDMg4 j8PNB9tXfVSlznKHwEwVZAU= =L2Lx -----END PGP SIGNATURE----- --nextPart12916457.GPyYVRSguV--