Reputation: 10161
is there any library that can inspect and display what are the arguments that a method takes?
Upvotes: 2
Views: 412
Reputation: 369468
I don't know of any third-party libraries or even RubyGems that can do this reliably. It just isn't possible to do this kind of inspection given the limited reflection facilities Ruby provides.
You will have to make do with what is available in the core library, which is basically Method#parameters
:
def foo(a, b=nil, *c, d, &e); end
method(:foo).parameters
# => [[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]]
Upvotes: 3
Reputation: 81520
There's Method#arity that lists how many arguments a method can take.
However, you can't determine what types of objects a method expects. That just isn't in the nature of Ruby.
Upvotes: 7