From: Brian Candler Date: 2007-02-06T20:13:31+09:00 Subject: Re: Proc vs lambda vs proc > (b) making such arguments explicitly ignorable at the caller side, which I > think I prefer. At worst: > > class Integer > def times(&blk) > if blk.arity == 1 > ... loop, yield with index > else > ... loop, yield without index > end > end > end or have a "yieldopt" statement, which does something like def yieldopt(*a, &blk) blk.arity == 0 ? blk.call() : blk.call(*a) end so the caller is saying that the callee can either have all of the arguments, or ignore them all. I can't think of any useful cases where an iterator calls a block with (say) three arguments, but the block only accepts two and is happy for the third to be silently ignored. If the block only accepts one argument, but yield passes more than one, this is currently treated as another special case: irb(main):001:0> h = {1=>"one", 2=>"two", 3=>"three"} => {1=>"one", 2=>"two", 3=>"three"} irb(main):002:0> h.each { |k| puts k.inspect } [1, "one"] [2, "two"] [3, "three"] => {1=>"one", 2=>"two", 3=>"three"} irb(main):003:0> This could be eliminated if people wrote h.each { |*k| .. I want an array .. } h.each { |k,v| .. I want separate items .. } which I think makes the intention very clear. Maybe this is already considered for 1.9 Cheers, Brian.