Obtaining number of block parameters
问题 I need to obtain the number of parameters a given block takes. For example: foobar(1,2,3) { |a, b, c| } def foobar(x, y, z, &block) # need to obtain number of arguments in block # which would be 3 in this example end This is possible in the 1.9 trunk, but not in any official release. I was hoping if there's any way to do this without having to download a separate gem/extension module. 回答1: When you materialize a block with &, it becomes a Proc object, which has an arity method. Just be