From: matz@... (Yukihiro Matsumoto) Date: 1999-05-14T16:16:50+09:00 Subject: [ruby-talk:00311] Re: help: iterator.. Hi. In message "[ruby-talk:00310] help: iterator.." on 99/05/14, Pros Yeboah writes: |How do one pass the one pass the block of an iterator recursively |further. |eg. |def foo(bar) |if bar <= 0; "baz" | else foo(bar-=1) ???? # ??? ==> the passed iterator block |end |end | |foo is supposed to be called with foo(something){block}. Hmm, there are two ways to accomplish this. (a) use tha passing block, like foo(bar-1) {|x| yield x} (b) use block argument to pass block. def foo(bar, &block) ... foo(bar-1,&block) ... end The former is pretty ugly, but runs bit faster. The latter is simpler but creation of the Proc object make it slower. |1) I don't want to use a Proc Object as a parameter. The second one objectifies the block into the Proc object, so it may not sufisfy you. |2) How can one refer to the object for the iterator block ? The block can be objectified by either: * calling lambda or proc or Proc.new without block within the iterator. * declaring block argument as formal argument of the method. Hope this helps you (and others). matz.