From: David Alan Black Date: 2001-08-16T00:23:34+09:00 Subject: [ruby-talk:19790] Re: 2 iterator questions Hello -- On Thu, 16 Aug 2001, Mark Slagell wrote: > I'm looking at some code in the FAQ (section 5) illustrating the > relationship between blocks and proc objects. Two questions come to mind: > > ------------------------------------- > 1. "An iterator is a method which accepts a block or a Proc object." How > to accept a proc object? I can't come up with working syntax. This > chokes, anyway: > > pr = proc {|x| x+1} > [1,2,3].each pr > > Since the error indicates that pr is being treated as a paramater, I tried > this > > [1,2,3].each() pr > > and got a parse error. On the other hand there's no problem sending a > proc object through the regular argument list: > > def iter(aproc) > aproc.call 17 > end > > iter pr #-> 18 > > Is that what is meant by saying iterators can accept proc objects? Try: [1,2,3].each &pr David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav