On Mar 20, 3:07=A0pm, Glenn Ritz <glenn_r... / yahoo.com> wrote:
> I have an array of objects, and the objects have some attributes. =A0I'd
> like to be able to modify selected elements in the array based on any of
> those attributes.

See Array#select and Array#find.

e.g.
albums.select{ |a| a.band=3D=3D"The Beatles" }.each{ |a| a.like=3Dtrue }

> Using collect like this works, but it seems awkward to me to have to
> iterate through the whole array just to find the element (or elements)
> that I want to change.

Without some previously-established alternative lookup mechanism, such
as a Hash, any implementation is going to have to walk through the
entire array to find multiple matching items. Array#find will stop as
soon as it finds one item, though.

For example (assuming you still need your albums array):

# Do this once
albums_by_band =3D albums.group_by{ |a| a.band }

# Do this for each time you need to look up an array of albums by a
band
albums_by_band["The Beatles"].each{ |a| a.like =3D true }