Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get documentation for a method in a Ruby gem?

I'm trying to find out about the can? method used by cancancan gem.

I tried here, but cannot locate the method can?:

enter image description here

As suggested here, I tried these:

can?.arity
NoMethodError: undefined method `can?' for main:Object

can?.parameters
NoMethodError: undefined method `can?' for main:Object

I'm simply trying to find out what parameters can? (the cancancan method used in the view) wants to receive, but this example is a good opportunity to learn how to do this for other methods as well, hence I hope for a general solution (one that will allow me to look up documentation for methods beyond the one asked in this specific example).

Thanks in advance for all help/pointers!

like image 520
stevec Avatar asked Aug 31 '20 16:08

stevec


1 Answers

As an alternative to using external sites, you can try ri from the command line:

ri "can?"

When you install a gem, the ri documentation is (usually) installed as well. The ri command line tool will search installed gem documentation for methods and constants matching your input and present them.

Since it runs locally, this can be a great resource when you don't have an internet connection handy!

enter image description here

like image 163
Chris Heald Avatar answered Oct 06 '22 23:10

Chris Heald