Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > method &block question

Reply
Thread Tools

method &block question

 
 
Simon Kröger
Guest
Posts: n/a
 
      01-04-2006
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()
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


 
Reply With Quote
 
 
 
 
Simon Kröger
Guest
Posts: n/a
 
      01-04-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dumb question: in documentation, why Object#method, and not Object.method ? Elf M. Sternberg Ruby 15 07-29-2009 01:20 AM
method def in method vs method def in block Kyung won Cheon Ruby 0 11-21-2008 08:48 AM
invoke a method by reflection£¬the method's parameters can not be ArrayList? jerry051 ASP .Net 2 08-02-2005 10:35 AM
Difference between Delete method and RemoveRow method CW ASP .Net 0 04-01-2004 01:07 AM
ASP.NET: BC30289: Statement cannot appear within a method body. End of method assumed. Mike Wilmot ASP .Net 0 12-15-2003 07:49 PM



Advertisments