From: Ryan Pavlik Date: 2003-01-30T05:29:35+09:00 Subject: Re: Local variables & blocks On Thu, 30 Jan 2003 01:46:54 +0900 ahoward wrote: Quote 1: > so, correct me if i am wrong, but this does not address the need to do > > x = nil > a.each do |item| > x = ... > end > p x > Quote 2: > > loop { export x; x = ... } > p x > Quote 3: > > x = nil > loop { x = ... } > p x > OK, this may seem an odd set of quotes, but I have a question. What happens when you do this: def munge(a) a.each { | i | export x; x = x + i } p x end ...and 'a' is empty? 'x' never happens. Now, you say that Quote 2 would be exactly identical to Quote 3, but it seems to me that it would be largely painful to search through scopes to make sure you catch all initializations: def quux() proc { export x; proc { export y; proc { export z; } } } end First of course is the question which scope each fall into (you said "local" scope so I assume #quux-wide), and then you'd have to make ruby hunt through all your blocks. Then what happens if you pass one as a parameter... where do exports go then? ;) Plus, there's the most important consideration: x = nil export x ^--- One extra character to type! ;-) -- Ryan Pavlik "Ha! Who needs wits when you've got swords!" - 8BT