From: Edward Faulkner Date: 2005-10-26T05:02:47+09:00 Subject: Re: Weird thing with "sub" and "rjust" --EY/WZ/HvNxOox07X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 26, 2005 at 04:52:02AM +0900, ricpelo@gmail.com wrote: > But it doesn't works with: >=20 > 'hello-3.jpg'.sub(/(\d+)/, '\1'.rjust(3, '0')) > =3D> "hello-03.jpg" The rjust is being evaluated before the sub call, so what you've written is equivalent to this: 'hello-3.jpg'.sub(/(\d+)/, "0\\1") Use the block form instead: 'hello-3.jpg'.sub(/(\d+)/) { $1.rjust(3, '0')} =3D> "hello-003.jpg" regards, Ed --EY/WZ/HvNxOox07X Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFDXo6ynhUz11p9MSARAsPNAKCd9sw3mtrviWTinfiO/NdM3pmZ4gCeOFBA MAkAnQEipYArKOrXreJ0lYA= =qRVa -----END PGP SIGNATURE----- --EY/WZ/HvNxOox07X--