From: Brian Candler Date: 2011-02-07T05:01:10+09:00 Subject: Re: pass the paramater? Bigmac Turdsplash wrote in post #979843: > mply=0 > kill=0 > open("list.lfi","rb").each do |block| > ['lol', '%00'].each do |suffix| > while mply < 10 > if block.include? ".log" > puts suffix > suffix > kill=1 > break > print("!!! Check your log.html !!!") > end > if kill==1; break;end > mply=mply+1 > end > if kill==1; break;end > mply=0 > end > if kill==1; break;end > end > > print suffix.last > > > > i always do things the hard way... i dont know how to get suffix out > side of the loop... If a local variable is first assigned to inside of a block, then its scope does not extend outside of the block (i.e. it's local to that block). So you can assign to it outside the block: foo = nil 10.times do |x| foo = x end puts foo # remembers value However, in this case 'suffix' is itself a block argument. In ruby 1.9, it's forced to be local to that block. In ruby 1.8 the block argument can be a variable which has already been assigned to, but that's bad practice. suffix = nil ['lol', '%00'].each do |suffix ... do stuff end puts suffix # doesn't work in ruby 1.9 So if you want the value of 'suffix' used in the last iteration of the loop, simply remember it explicitly. last_suffix = nil ['lol', '%00'].each do |suffix| last_suffix = suffix ... do stuff end puts last_suffix -- Posted via http://www.ruby-forum.com/.