From: Eric Hodel Date: 2003-12-15T15:12:25-08:00 Subject: Re: [Nuby] Object ID Lookup? --bmlge7Pg4VPvffji Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Jim Moy (web@jimmoy.com) wrote: > Hi all, a Ruby Nuby here with a question. >=20 > Is there a way to lookup an object reference from the object's id?=20 > Something to do like the following, but without the need for the lookup > hash: >=20 > a =3D { "a" =3D> 1, "b" =3D> 2 } > b =3D { "c" =3D> 4, "d" =3D> 3 } > arr =3D [a, b] > ids =3D arr.collect {|h| h.id} > lookup =3D {} > arr.each { |h| lookup[h.id] =3D h } > cmp =3D ids.collect {|id| lookup[id]} > ids =3D=3D cmp =3D> true >=20 > In my instance, I've got a reference set of hashes that I'm pointing to > from multiple arrays. Those arrays are manipulated depending on sorting > and other factors. >=20 > I don't want to get Hash#=3D=3D involved so I'm using the Hash object id'= s.=20 > After processing is completed, I'd like to get back from the IDs to the > object references. The lookup is working, but I was wondering if there > was a better method. Not seeing the internals of your code, will Object#equal? (identical object ids) be able to replace #=3D=3D? --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --bmlge7Pg4VPvffji Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQE/3j/ZMypVHHlsnwQRAqq6AJ0UvivlN563tHun7GtAvVRVydxsjACfZo40 bv58DcgrBN00bjUjX/vURvk= =mm3r -----END PGP SIGNATURE----- --bmlge7Pg4VPvffji--