Reputation: 10235
I'm trying to get a list of the methods defined in our Rails codebase, without including anything defined in superclass or dynamically defined at runtime. I've tried instance_methods(false)
, but a ton of methods are returned:
> User.instance_methods(false).length
=> 310
I'm guessing this is because Rails defines a bunch of methods at runtime. Is there any way to get a list of the methods only defined in the files in our app? Hoping there's a Ruby way and not just running a grep across all of the files. Bonus points for class methods as well...
Upvotes: 1
Views: 83
Reputation: 21
Use MyClass.instance_methods(false)
, but make sure to pass false
as an argument if you don't want it to return the methods defined in the superclasses.
Additionally, use MyClass.singleton_methods(false)
for class methods.
More info:
Upvotes: 0
Reputation: 1392
User.instance_methods
will show all the inherited methods as well, so you should run something like that
User.instance_methods - User.superclass.instance_methods
Be ware thought that it will show heaps of other methods that are generated by AR when you inherited the ActiveRecord::Base
class
Upvotes: 1