From: Bill Kelly Date: 2008-04-25T01:16:11+09:00 Subject: Re: Pointer concept in Ruby ? From: "I単aki Baz Castillo" > > Hi, I'd like to have a variable pointing to a Hash/Array element, so > if I modify the variable then the Hash/Array element is modified too. > > AFAIK this is not possible with Ruby since the abscense of pointer > concept. I want the following: > > array = [ "aaa", "bbb", "ccc" ] > > a1 = array[1]._some_method_ > => "bbb" > > a1 = "BBB" > => "BBB" > > a[1] > => "BBB" > > Is it possible in some way? Thanks a lot. In general this not easily possible with Ruby, and you'll probably want to rethink your design so that you don't need to do that. However, there is a String#replace method, which may be useful if you're sure this is what you want to do: => ["aaa", "bbb", "ccc"] >> a1 = array[1] => "bbb" >> a1.replace "BBB" => "BBB" >> array[1] => "BBB" Regards, Bill