From: Kristof Bastiaensen Date: 2004-08-05T20:56:35+09:00 Subject: Re: Macros in Ruby On Thu, 05 Aug 2004 12:15:20 +0200, Robert Klemme wrote: >> The difference which I can think of are: - Argument passing, a block >> isn't strict about the arguments >> it gets passed, (i.e. it can take any argument). A Proc object in >> contrast is strict (like methods). The reason I can think of is that >> it is often usefull not to get all arguments in a block, i.e. 3.times{ >> puts "Hi, world!" } > > I don't know what exactly you mean by this. Argument passing is the same > for blocks and procs IMHO. Can you explain the difference? Oh, it seems I was wrong (after looking it up with ri). What I said in the previous post only applies to procs created with lambda (including the return thing), not procs created with Proc.new. So I guess that Proc.new creates exactly the same Proc object as a block does (in the case that a Proc object gets created from a block). Only lambda expressions are different. That would also mean that the best way to get rid of the LocalJumpError problem is to use a lambda expression. Here is an example about what I meant with argument passing: b1 = Proc.new { |a,b| puts "a == #{a.inspect}, b == #{b.inspect}" } b2 = lambda { |a,b| puts "a == #{a.inspect}, b == #{b.inspect}" } b1[1] b2[1] #--- output: ---- a == 1, b == nil /tmp/blocks.rb:5: wrong number of arguments (1 for 2) (ArgumentError) from /tmp/blocks.rb:5:in `[]' from /tmp/blocks.rb:9 #---------------- Sorry for the confusion. Cheers, KB