Aaron Yodaiken
Aaron Yodaiken

Reputation: 19551

How to determine the number of accepted arguments in a lambda in ruby

Is there any method or something x in which, provided z = lambda {|x, y, z| nil} we can say

z.x #=> 3

Of course, syntax can differ if it gets the job done. Thank you!

Upvotes: 2

Views: 119

Answers (2)

Mark Rushakoff
Mark Rushakoff

Reputation: 258288

The Proc#arity method tells you this:

ruby-1.9.1-p378 > f = lambda { |x,y,z| nil }
 => #<Proc:0x000001009ca830@(irb):1 (lambda)> 
ruby-1.9.1-p378 > f.arity
 => 3 

Upvotes: 4

Adrian
Adrian

Reputation: 15171

Yes.

z.arity #=> 3

Upvotes: 8

Related Questions