From: "Alizée Penel" Date: 2011-02-03T21:55:39+09:00 Subject: Class Instanciation in loop 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. Here is the output I have: Good Tests : Subgroup name: Subgp2 File: file2 Bad Tests : Subgroup name: Subgp2 File: file2 Here is the output I want: Good Tests : Subgroup name: Subgp1 File: file1 Bad Tests : Subgroup name: Subgp2 File: file2 Can you explain me why I have this behaviour in my script ? Thanks by advance ! -- Posted via http://www.ruby-forum.com/.