A
anne001
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
def run
data="hello dud"
data.split(/</).each do |line|
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(/</).each do |chunk|
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
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
def run
data="hello dud"
data.split(/</).each do |line|
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(/</).each do |chunk|
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