method &block question

S

Simon Kröger

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
 
S

Simon Kröger

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Logic Problem with BigInteger Method 2
each by arity 17
yield/block question 5
Minimum Total Difficulty 0
Method error 0
Block variables 2
Help with code 0
grep a block 4

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top