[#964] Bastion or SecurityManager for Ruby? — Clemens Hintze <clemens.hintze@...>

Hi,

15 messages 1999/12/10

[#989] a question about to_i — Friedrich Dominicus <Friedrich.Dominicus@...>

Sorry, I'm quite new to ruby. But I encounterd the following problem. If

17 messages 1999/12/19

[ruby-talk:01012] Re: Blocks, Procs, and iterators

From: matz@... (Yukihiro Matsumoto)
Date: 1999-12-31 07:52:58 UTC
List: ruby-talk #1012
In message "[ruby-talk:01008] Blocks, Procs, and iterators"
    on 99/12/30, Dave Thomas <Dave@thomases.com> writes:

|Is there a difference between
|
|  def fred
|    yield 1
|    yield 2
|  end
|
|and
|
|  def fred(&block)
|    block.call(1)
|    block.call(2)
|  end

Almost same.  The differences are 

  (1) &block create a Proc object, yield does not; thus yield version
      is bit faster.

  (2) With &block, you can check the number of parameters (variables
      surrounded by | |) in block with Proc#arity method.  There's no
      such way for a unobjectified block.

  (3) It's much easier to pass a block to another method with &block.

Hope this helps.

							matz.

In This Thread