From: Stefano Crocco Date: 2011-02-04T17:03:17+09:00 Subject: Re: Class Instanciation in loop On Thursday 03 February 2011 21:55:39 Alizée Penel wrote: > Hi everyone ! > > I am a beginner in Ruby and i am faced to a problem I do not understand. > > I have two classes: Subset, Parser > Parser class parses an array (tab) which contains worlds from a file and > creates > Subset objects and adds them in two others arrays (@@good, @@bad). > > This file looks like: > Good > { > Subgp1 > { > file1 > } > } > Bad > { > Subgp2 > { > file2 > } > } > > For example : > > j = tab.find_index("Bad") > i = 1 > while i < tab.size do > c = Subset.new(tab[i]) > i = i + 1 > # This method parse is a subparser which parse the containning of SubgpX > # elements (here, file1 and file2) and put them in an Subset class > array. > i = c.parse(tab, i) > if tab[i] < j then > @good << c > else > @@bad << c > end > i = i + 1 > end > > When I do a prettyprint of @@good and @@bad, @@good have the same > elements as > in @@bad, and others elements which should be in @@good disappeared. I think there's a typo in your code: @good << c should be @@good << c Stefano