Monday, January 07, 2008

For Loops considered obsolete

From my point of view one of the odder things about Ruby is that 'for loops' are obsolete . . .

If you're still writing for loops, stop; there's a better way. Exactly why merits some examples.

[1, 2, 3].each { |number| puts number }
That's a pretty straightforward one. It says: with each element in this array, execute the given block.

That's just darn weird. I'm sure I'll get used to it.
blog comments powered by Disqus