From: Adam Shelly Date: 2008-04-25T05:54:55+09:00 Subject: Re: Pointer concept in Ruby ? On 4/24/08, Iņaki Baz Castillo wrote: > Isn't there any mehotd more "normal"? something as: > > a2 = array[2]._something_ > > a2="QWE" > > array[2] > => "QWE" > There are probabaly a million reasons this is a bad idea, but what about: require 'ptrclass' => true a = [0,1,2,3] => [0, 1, 2, 3] ap = a.ptr(3) => 3 ap.val=4 => 4 a => [0, 1, 2, 4] r=a.ptr(6) => nil r.val=4 => 4 a => [1, 34, 3, nil, nil, nil, 4] --- ptrclass.rb---- class PtrClass < DelegateClass(Object) def initialize v super __setobj__ v end def val= v __setobj__ v end end class Array def ptr n v= self[n] self[n] = v.is_a?(PtrClass) ? v : PtrClass.new(v) end end --- -Adam