From: Eric Hodel Date: 2003-10-15T16:26:17-07:00 Subject: Re: General Ruby Programming questions --gRZ38brEgCoUohoa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Florian Gross (flgr@ccan.de) wrote: > Simon Kitching wrote: > > >(b) changing "require" searchpath > >The $: variable holds the path used to locate files when the "require" > >command is used. However this variable is read-only. In Perl, it is > >possible to modify the equivalent path; can this be done in ruby? >=20 > It might be read-only, but that doesn't mean that you can't change the=20 > object which it refers to: >=20 > irb(main):002:0> $:.push('new') > =3D> [..., 'new'] You really want to unshift here, the Array is read front to back, so new libs that override base libs won't get require'd. > >(d) iterating in reverse=20 > >I have an Array object, and wish to iterate over its members in reverse. > >I would prefer not to have to create a new Array object in order to do > >this iteration. Is there any way other than writing >=20 > irb(main):004:0> [1, 2, 3].reverse_each { |item| puts item } > 3 > 2 > 1 You can also use reverse. An Array is smart, reverse takes constant time. [1,2,3].reverse.map do |i| i * 2 end --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --gRZ38brEgCoUohoa Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQE/jdeZMypVHHlsnwQRAr3HAKCKrbnPdL6qsRPy4hO4Bfe0OvXqwACg39Ja BnyNvXWDbaq1d1ia1wzhoks= =k36U -----END PGP SIGNATURE----- --gRZ38brEgCoUohoa--