method &block question

Discussion in 'Ruby' started by Simon Kröger, Jan 4, 2006.

  1. Hi,

    could someone please put a finger on the point i'm missing?

    source:
    ------------------------------------
    def test *a
    p a
    end

    [[1,2], [3,4]].each &method:)test)
    puts "-----"
    [[1,2], [3,4]].each &method:)p)
    puts "-----"
    [[1,2], [3,4]].each {|e| p e}

    ------------------------------------

    output:
    ------------------------------------
    [1, 2]
    [3, 4]
    -----
    1
    2
    3
    4
    -----
    [1, 2]
    [3, 4]
    ------------------------------------

    ruby 1.8.2 (2004-12-25) [i386-mswin32]

    Why is the second version interating over each single element?

    cheers

    Simon
    Simon Kröger, Jan 4, 2006
    #1
    1. Advertising

  2. Simon Kr=F6ger wrote:


    > [...]=20
    > Why is the second version interating over each single element?


    It does not, the array is simply splashed when passed to 'p', so p
    sees two parameters and print them...

    Sorry for the noise.

    cheers

    Simon
    Simon Kröger, Jan 4, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper
    Replies:
    1
    Views:
    703
    Showjumper
    Mar 19, 2005
  2. Noozer

    Block DIV within a block DIV?

    Noozer, Jan 6, 2005, in forum: HTML
    Replies:
    3
    Views:
    11,366
    Mitja
    Jan 6, 2005
  3. morrell
    Replies:
    1
    Views:
    949
    roy axenov
    Oct 10, 2006
  4. John J. Franey
    Replies:
    3
    Views:
    133
    George
    Jun 15, 2007
  5. Kyung won Cheon
    Replies:
    0
    Views:
    204
    Kyung won Cheon
    Nov 21, 2008
Loading...

Share This Page