From: The Higgs bozo Date: 2008-10-28T04:12:53+09:00 Subject: Re: Quick Scope Question David A. Black wrote: > On Tue, 28 Oct 2008, Daniel Malcolm Webb [dbw] wrote: >> Q_txt = res_q[0][1] >> (0..10).each do |qt| >> question_text = q_txt.scan(/\w+/)[qt] >> end >> >> when I access question_text after, obviously it's out of scope what am I >> missing here? > > Blocks have a kind of one-way valve local scope. Variables that > already exist before the block will exist in the block. Variables that > are created in the block do not survive past the block. This is one reason I prefer {...} instead of do...end for blocks, since for me the curly braces shout "new scope". while...end, for...end, until...end, if...end, unless...end do not introduce new scopes, yet do...end does. Though class...end, module...end, def...end also give new scopes, there is little room for confusion because those are not control structures. -- Posted via http://www.ruby-forum.com/.