millisami
millisami

Reputation: 10161

Any ruby library to inspect what are the arguments that a certain methods take?

is there any library that can inspect and display what are the arguments that a method takes?

Upvotes: 2

Views: 412

Answers (2)

Jörg W Mittag
Jörg W Mittag

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

Andrew Grimm
Andrew Grimm

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

Related Questions