On Wed, Jul 09, 2003 at 06:05:42AM +0900, Grzegorz Dostatni wrote:
> I need to do something silly.  I need to access the code block as a
> variable (to pass it - without evaluating - to another function).  How can
> I do that?

It's not silly at all, but the syntax isn't obvious if you haven't seen it
before.

At the end of your argument list give a named argument preceded with '&'.
This converts the block to an explicit Proc object which you can pass
around.

  def function1(&blk)
    function2(blk)
  end

  def function2(blk)
    blk.call(99)
  end

  function1 { |i| puts i }    #>> prints 99


> Is it possible for me to access the "text version of block?" Can I print
> out the code that has been attached to my function instead of executing
> it?

No, decompiling blocks is not possible AFAIK :-)

Regards,

Brian.