From: Brian Candler Date: 2008-10-01T17:32:56+09:00 Subject: Re: ruby1.9 block scope Daniel DeLorme wrote: > 1 collection.each do |element| > 2 changed = true if element.change > 3 end > 4 do_something if changed > > Are you really saying that upon reading line 4 you have to backtrack to > line 2 in order to understand this code? I think the point is more this: class Foo attr_reader :changed def update collection.each do |element| element << "\n" if changed # <<<< end ... ... ... collection.each do |element| changed = true if element.change end end end At the marked line, you can't tell whether 'changed' is a local variable or a method call on this object until you have read forward to the end of the method. For me, this is horrid. Perhaps more importantly though, as far as I can see it makes irb pretty useless, since it can't predict the future. What's supposed to happen when you type this, one line at a time? def tmp; "hello"; end m = lambda { |x| tmp + x } m[" world"] tmp = "goodbye" m[" world"] This particular example may be somewhat contrived, but if code behaves differently in irb than when read from a source file, that would be horrid (and difficult to explain) too. Regards, Brian. -- Posted via http://www.ruby-forum.com/.