Reputation: 3523
Is there a way to list all class and instance methods (separately) that are implemented in a Rails 5 model, while excluding inherited methods, methods provided by mixins, attribute accessors, ActiveRecord callbacks and any other methods that were not explicitly implemented in the model? In other words, if there is no def some_method
statement within the model file, then some_method
should not be listed.
Thank you.
Upvotes: 1
Views: 129
Reputation: 6489
For the class methods:
module_methods = Model.included_modules.map(&:methods)
Model.methods - Model.superclass.methods - module_methods
For some model Model. And you can use instance_methods
for the instance methods.
Upvotes: 2