From: Alan Chen Date: 2002-05-30T07:30:55+09:00 Subject: Re: object-name = content of a variable (migration from perl) On Thu, May 30, 2002 at 06:43:32AM +0900, Marc Rene Arns wrote: > I'm not sure if you got me right. The dynamically changing array-names > was in respect to the abilities of PERL. > The idea to do it in ruby was to create new objects of the same class in > a loop, but the number of objects is generated automatically changing > (value of a variable) and also a part of the object-names should reflect > a running number, so that later I would be able to read in a loop (who is > changing the number) object by object with their parameters, s.th. Like > this > p = 'name' > i = 0 > while (weather == fine) > o_name = p+i > o_name = test.new('give me', 'some parameters') > i += 1 > end > what should create the objects name0, name1, etc. all belonging to the > same class test. Unless there is some driving need (convenience is a need :) to use dynamic names, you could do this: objs = List.new # [] works too 10.times { |i| objs << Test.new('give me', 'some parameters') } Objects created this way could be accessed in the list like this: objs.each { |ob| ob.mymethod( arg1, arg2) } or maybe objs.each { |ob| if( ob.changed? ) # do something end } ... and if you need to access an individual object in the list objs[5].mymethod(arg3, arg4) -- Alan Chen Digikata LLC http://digikata.com