From: Robert Klemme Date: 2008-01-05T05:04:57+09:00 Subject: Re: iterating over array of variables - can't change them? On 04.01.2008 18:36, Ken Bloom wrote: > On Fri, 04 Jan 2008 08:06:38 -0800, 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? >> >> thanks > > Refer to the variables as strings and use eval. > > ["title","subtitle","body"].each {|item| eval "#{item}=''"} I believe this is rather inefficient (aka slow) and more importantly will not run under all circumstances ($SAFE). Plus, it's not needed. :-) Kind regards robert