From: Robert Klemme Date: 2008-10-28T22:32:29+09:00 Subject: Re: Quick Scope Question 2008/10/27 David A. Black : > Hi -- > > 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? Not what you asked for, but: "Q_txt" != "q_txt". Also, you should do the scan only once - this is more efficient: texts = res_q[0][1].scan(/\w+/) texts.each_with_index do |question_text, qt| ... end > 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. Which is basically the same in many modern programming languages, isn't it? Of course, there are some subtleties (e.g. whether shadowing of more local definitions is allowed etc.). Kind regards robert -- remember.guy do |as, often| as.you_can - without end