[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

method &block question

Simon Kröger

1/4/2006 8:31:00 PM

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


1 Answer

Simon Kröger

1/4/2006 8:39:00 PM

0

Simon Kröger wrote:


> [...]
> 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