From: Mohamed Dokmak Date: 2014-04-14T10:06:39-07:00 Subject: [ruby-core:62024] Question about Ruby Arrays --1747921928-2107861070-1397495199=:31561 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi,=0A=0AI'm trying to implement a functionality that hooks on array modifi= cations "by reference" but I find it complicated to implement such hook.=0A= =0AEx :=A0=0A=0Aarr =3D [12 , "hello" ]=0A=0Aarr.reverse!=0Aarr.reverse=0A= =0A=0AThe first one will reverse the array by reference "same VALUE" withou= t creating a new object but just modifying its value by its reference " sam= e as opt_aset YARV instruction ".=0A=0AThe second will create a new array i= nstance and return a different reference "VALUE" holding the change.=0A=0AI= s there another way that could help me implement such a hook ? possibly a m= ethod I haven't discovered yet ? I've looked at rb_ary_modify_check but it'= s much related to shared arrays.=0A=0AI need ideas on implementing a hook t= hat enables me to know when Ruby uses a method dispatch such as arr.reverse= ! and return the same reference to the object ?=0A=0A--=0AMohamed Dokmak --1747921928-2107861070-1397495199=:31561 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,

I'm trying to implement a functionality that hooks on array = modifications "by reference" but I find it complicated to implement such ho= ok.

Ex : 

arr =3D [12 , "hello" ]

arr.revers= e


The first one will reverse the array by reference "same = VALUE" without creating a new object but just modifying its value by its re= ference " same as opt_aset YARV instruction ".

The second will create a new array instance and return a different r= eference "VALUE" holding the change.

Is t= here another way that could help me implement such a hook ? possibly a meth= od I haven't discovered yet ? I've looked at rb_ary_modify_check but it's much related to shared arrays.

I need id= eas on implementing a hook that enables me to know when Ruby uses a method = dispatch such as arr.reverse! and return the same reference to the object ?=

--
Mohamed Dokmak
 
--1747921928-2107861070-1397495199=:31561--