From: Robert Klemme Date: 2008-01-05T01:25:00+09:00 Subject: Re: iterating over array of variables - can't change t hem? On 04.01.2008 17:06, AJS wrote: > title="Title" > subtitle="Subtitle" > body="Body" > [title,subtitle,body].each {|item| item.downcase!} > > This successfully sets the original variables to "title", "subtitle", > "body" > > BUT > > [title,subtitle,body].each {|item| item=""} > > has no effect. > > Why doesn't this work? How can I make it work? It does not work because you assign to "item" which is a local variable in the block. And since you do not change string objects in the Array you do not see any change. In your case you should change the original object, e.g. [title,subtitle,body].each {|item| item.replace ""} [title,subtitle,body].each {|item| item.sub! /.*/, ""} More generally you can also change the array via assignment by doing an_array.map! { "" } But this again won't change the objects referenced by "title" etc. HTH robert