On Wed, 4 Aug 2010, Marnen Laibow-Koser wrote:
…which I do. But for…in just doesn’t feel like a good fit for Ruby
to me – it feels more like syntactic sugar for Perl and PHP
Evidence for that can be found in the fact that for is implemented in
terms of each:
obj = Object.new
puts “Here I am in each, about to yield 100!”
for a in obj
Here I am in each, about to yield 100!
$ ruby -e ‘for a in 3; end’
<main>': undefined methodeach’ for 3:Fixnum
There’s a slight difference in how they work, in the sense that each
takes a code block (at least, as usually implemented), while for is in
flat scope, similar to an if-statement:
for a in 
b = 100
p b # 100
I don’t know of any cases where having the flat scope would be so
important as to lead me to use for if I didn’t have some other reason to
(which I don’t think I ever have).
David A. Black, Senior Developer, Cyrus Innovation Inc.
The Ruby training with Black/Brown/McAnally
Compleat Philadelphia, PA, October 1-2, 2010