From: Eric Hodel Date: 2003-02-04T07:18:29+09:00 Subject: Re: What is a tuple? --K5roPakIqCb4O6y8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Mark Wilson (mwilson13@cox.net) wrote: >=20 > On Monday, February 3, 2003, at 04:35 PM, Bob X wrote: >=20 > >[snip] >=20 > >Tuples are immutable lists. > > > >"Tuples have many uses. For example: (x, y) coordinate pairs, employee > >records from a database, etc. Tuples, like strings, are immutable: it=20 > >is not possible to assign to the individual items of a tuple (you can=20 > >simulate much of the same effect with slicing and concatenation,=20 > >though). It is also possible to create tuples which contain mutable=20 > >objects, such as lists." > ><-- from Python docs >=20 > Thank you for the prompt response. Could one then implement a tuple in= =20 > Ruby as follows: >=20 > class Tuple >=20 > attr_reader :tuple >=20 > def initialize(*args) > @tuple =3D *args > end > end no, that's not immutable, you need something more like this: module Enumerable def deepfreeze self.each do |o| if o !=3D self then=20 o.deepfreeze else o.freeze end end self.freeze end end class Object def deepfreeze self.freeze end end class Tuple < Array def initialize(*stuff) super() self.push(*stuff) self.deepfreeze end end (comes from here) http://sourceforge.net/project/shownotes.php?group_id=3D50485&release_id=3D= 124575 --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --K5roPakIqCb4O6y8 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (FreeBSD) iD8DBQE+PuqzMypVHHlsnwQRAvx4AKDNrCZ8v8fnEO04KATH4MziFrwKngCgoMwc cTcwuVb879t2jZXfN+10aao= =BCsW -----END PGP SIGNATURE----- --K5roPakIqCb4O6y8--