From: Michael Guterl Date: 2006-07-09T23:45:37+09:00 Subject: Re: why does block know about one instance variable and not the other? ------=_Part_128256_32185647.1152456330799 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, On 7/9/06, anne001 wrote: > > I can't find what the problem is with @foundinfo: since it is defined > outside a block, the block should find it no? @item is defined outside > the second block and that second block finds it. What is @item and > @foundinfo different? > > Do I have a typo I don't see, or it there a principle of the thing? > > Here is my simplified code with debugging puts > > class Linear > @foundinfo=Hash.new > p " 1. debugging @foundinfo created" > p @foundinfo.class #this is ok You should wrap the above section in the initialize method, like so. def initialize @foundinfo = Hash.new p " 1. debugging @foundinfo created" p @foundinfo.class #this is ok end def run > > data="hello dud" > data.split(/ line =~ /d(.)d/ > @item=$1 > p "2. debugging, @foundinfo found?" > p @foundinfo.class # this is not ok, @foundinfo not found > > lines="and so on and some more" > lines.split(/ p "3. debugging, @item found?" > p @item #this is ok, @item found > p "3. debugging, @foundinfo found?" > p @foundinfo.class # this is still not ok, @foundinfo > not found > end # end do chunk > end # end do line > end # end run > > end # end class > > a=Linear.new > a.run > > > Michael Guterl ------=_Part_128256_32185647.1152456330799--