From: Suraj Kurapati Date: 2007-12-12T09:51:36+09:00 Subject: Re: Creating multiple objects in loops Richard Harris wrote: > #array[1] has the value "a", create a new object with the name "a" > #e.g. a = Object.new > > Whatever I try doesn't seem to work so I don't know if there is any way > of doing it. Yes, the problem you pose is very well solvable (see below), but ... what exactly are you trying to accomplish by dynamically defining named local variables? A wise Rubyist once said "eval is evil", so beware! >> array = %w[a b c] => ["a", "b", "c"] >> array.map {|x| "#{x} = Object.new" } => ["a = Object.new", "b = Object.new", "c = Object.new"] >> array.map {|x| "#{x} = Object.new" }.join('; ') => "a = Object.new; b = Object.new; c = Object.new" >> eval array.map {|x| "#{x} = Object.new" }.join('; ') => # >> a => # >> b => # >> c => # -- Posted via http://www.ruby-forum.com/.