Ognjen Regoje bio photo

Ognjen Regoje
But you can call me Oggy


I make things that run on the web (mostly).
More ABOUT me and my PROJECTS.

me@ognjen.io LinkedIn

Getting all methods in rails

#rails #technical

For controllers

PagesController.instance_methods - ActionController::Base.instance_methods - ApplicationController.instance_methods

For models

exclude = Regexp.union ['before_add', 'after_add', 'before_remove', 'after_remove']
(Page.methods(false) - ApplicationRecord.instance_methods - ActiveRecord::Base.methods(true)).reject{|x| x.match? exclude }

Page is the model.

The exclude is needed to remove all the callbacks for related associations.

Note that this also includes the named scopes, and I’ve not found a way to exclude them yet.

Other objects (such as services)

PagesService.methods(false) + PagesService.instance_methods