From: matz@... (Yukihiro Matsumoto) Date: 1999-05-17T18:56:58+09:00 Subject: [ruby-talk:00320] Re: Arity features for Proc object? Hi. In message "[ruby-talk:00319] Re: Arity features for Proc object?" on 99/05/17, GOTO Kentaro writes: |>I see. Thank you. I expected you to answer this question, Gotoken. | |Aha, I felt that I was called :-) Thank you for your kindness and help all the time, especially for mathematical topics. |>Parameter assignment for blocks is done by multiple assignment, which |>does not do the number check. I know it's little bit weird for Proc |>objects, but the Proc is relatively new feature to Ruby. I couldn't |>ignore compatibility. I would add argument number check to the Proc |>objects in the future version, maybe. | |I hope so. But it might cause serious incompatibility to earlier |versions because Proc.new{|i|...} can receive .call(a,b) as an array. |We should have discussions. Well, well, I opened eval.c to see how hard to implement arity and arugument check for block evaluation, and then spent about 1 hour, now you see, it's done. :-) I defined two methods, Proc#arity, and Method#arity, which return the number of required arguments for the Proc and Method objects. If they accepts variable number of arguments, the arity return negative number. And added some checking code to the function massign() to accomplish argument check like methods. Of cource you can't detect proc = Proc.new{|i| ..} proc.call(a,b) because it's completely legal. But: proc = Proc.new{|i,| ..} # explicitly declare single argument proc.call(a,b) and proc = Proc.new{|i,j| ..} # more than two arguments proc.call(a,b,c) will cause ArgumentError exception, just like methods. I think it does not break any existing code. matz.