From: Joel VanderWerf Date: 2009-06-19T03:47:43+09:00 Subject: Re: Modifying data in an array using a reference Ch Ba wrote: > Ok so my situation is as follows. I have an array "foo", which contains > several instances of the class "bar". I get a copy of an object inside > of "foo" using foo.detect, and then modify that copy. Afterwards, I > need to replace the original inside the array with the modified version. > The problem is that I do not know the index of the object. How would I > go about doing that? I could use some help =) You're working with the original foo, not a copy, so you don't need to replace the entry at a certain index: class Bar attr_accessor :x def initialize x @x = x end end foo = [Bar.new(0), Bar.new(1)] p foo bar = foo.detect {|bar| bar.x > 0} bar.x = "changed" p foo [#, #] [#, #] -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407