From: gwtmp01@... Date: 2006-09-11T11:52:18+09:00 Subject: Re: Struggling with Blocks On Sep 10, 2006, at 6:45 PM, Paul Lutus wrote: > "do" reads from a list of items and provides them to its > controlling block: > > (implicit "do") > > array.each { |item| > # do something here > } > > (explicit "do") > > array.each do |item| > # do something here > end > > These two forms are interchangeable. One can argue that "do" is an > implicit > "{ ... }" block, or the reverse. But the point is "do" receives > items and > operates on them one at a time, then exits when its stream is empty. This just doesn't sound right to me. do/end and {} are part of the syntax of a method call in ruby. They aren't operators. There is no requirement that the code in a do/end or {} block be used within some sort of a looping or iterative context. For example: File.open('datafile') do |fd| # do something with the open file handle: fd end A do/end block is simply a snippet of code and a set of variable bindings that are made available to the called method. The called method can ignore the block, call it one or more times, call it conditionally, pass it along to some other method, and so on. Gary Wright