From: Devin Mullins Date: 2005-06-27T10:50:08+09:00 Subject: Re: newbie scope question Wow, that was a simple and complete summary of scope in Ruby. That helps a lot. :) I had known that variables defined inside blocks didn't escape blocks. I didn't know that the same wasn't true for loops and conditionals. Essentially, scope is flat inside a class/module/method, with the odd exception of blocks. This is good, except it makes blocks a little confusing Example #1: irb(main):001:0> a = nil => nil irb(main):002:0> 5.times {|a| } => 5 irb(main):003:0> a => 4 Example #2: irb(main):006:0> 5.times { irb(main):007:1* a ||= 0 irb(main):008:1> a+=1 irb(main):009:1> print a, ' ' irb(main):010:1> } 1 1 1 1 1 Example #3: irb(main):001:0> a = 0 => 0 irb(main):002:0> 5.times { irb(main):003:1* a ||= 0 irb(main):004:1> a+=1 irb(main):005:1> print a, ' ' irb(main):006:1> } 1 2 3 4 5 Not a huge issue. Just something to get used to. Devin