From: "Ara.T.Howard" Date: 2005-06-03T07:54:51+09:00 Subject: Re: Implementing a Read-Only array --8323328-1709284869-1117752889=:2568 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1709284869-1117752889=:2568" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1709284869-1117752889=:2568 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Fri, 3 Jun 2005, Gavin Kistner wrote: > On Jun 2, 2005, at 11:22 AM, Brian Schr=F6der wrote: >> Just playing devils advocate here, but if you care about user added >> methods, the user may also add something that acts in effekt like >>=20 >> class Array >> def mutate(i, v) >> self[i] =3D v >> end >> end > > Duly noted and understood. > > However...if I've undef'd #[]=3D, then that won't work, right? > > > irb(main):003:0> class Array; def mutate(i,v); self[i]=3Dv; end; end > > irb(main):004:0> a =3D [] > > irb(main):005:0> class << a; undef_method( :'[]=3D' ); end > > irb(main):008:0> a[0] =3D 0 > NoMethodError: undefined method `[]=3D' for []:Array > from (irb):8 > > irb(main):009:0> a.mutate(0,0) > NoMethodError: undefined method `[]=3D' for []:Array > from (irb):2:in `mutate' > from (irb):9 but that means that not even you can mutate it. if not even you can mutate= it why not just use Object#freeze? -a --=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D --8323328-1709284869-1117752889=:2568-- --8323328-1709284869-1117752889=:2568--