From: botp Date: 2011-02-04T17:49:44+09:00 Subject: Re: Class Instanciation in loop On Fri, Feb 4, 2011 at 3:30 PM, Alizée Penel wrote: > Nobody wants to help me ? Hi Alizee, maybe because you did not provide all the relevant data/codes/classes/ concerning the particular problem. it is time consuming if we just guess.. anyway, the ff is a sample test on my irb console. just thought you might compare it w your scheme, > File.open("filetest.txt","r"){|f| puts f.read} Good { Subgp1 { file1 } } Bad { Subgp2 { file2 } } #=> nil File.open("filetest.txt","r"){|f| s=f.read} #=> "Good\n{\n Subgp1\n {\n file1\n }\n}\nBad\n{\n Subgp2\n {\n file2\n }\n}" s #=> "Good\n{\n Subgp1\n {\n file1\n }\n}\nBad\n{\n Subgp2\n {\n file2\n }\n}" File.open("filetest2.txt","w") do |f| s.scan(/(\w+)\n\{\s*(\w+)\s*\{\s*(\w+)\s*\}\s*\}/mx).each do |group,subgroup,file| f.write "Group:#{group}\n\tSubgroup:#{subgroup}\n\t\tFile:#{file}\n" end end #=> [["Good", "Subgp1", "file1"], ["Bad", "Subgp2", "file2"]] File.open("filetest2.txt","r") do |f| puts f.read end Group:Good Subgroup:Subgp1 File:file1 Group:Bad Subgroup:Subgp2 File:file2 #=> nil best regards -botp