From: Daniel DeLorme Date: 2008-10-01T13:51:38+09:00 Subject: Re: ruby1.9 block scope Mike Gold wrote: > Yukihiro Matsumoto wrote: >> Yes, but >> >> * Class.new and define_method is a rather rare examples, of which >> non-block counterpart introduce new scopes. > > But it's not a rare example for me. It's a great solution to an > otherwise tangled problem. When I have more time I can post some code > if my example is not convincing. Yes, I would love to see some non-contrived example code. I don't use define_method very often and I have hardly ever used Class.new, certainly not with several levels of nested blocks. The common case for which I *would* like to use this suggested featured is something like this: 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? Far from a monster of O(n^2) complexity, this is the kind of code that most programmers would expect to work. Except it doesn't, and if I have to hazard a guess I would say that 90% of ruby newbies have run into that gotcha. Of course we all learn to work around it and even exploit it, but it doesn't mean it was right to begin with. While "intuitive" and "POLS" are loaded terms, if 90% of newbies bump into a gotcha, IMHO it's the sign of a design flaw, and matz was right to notice it. -- Daniel