How do I list all the methods that a particular object has access to?
I have a @current_user object, defined in the application controller:
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
And want to see what methods I have available to me in the view file. Specifically, I want to see what methods a :has_many association provides. (I know what :has_many should provide, but want to check that.)
The following will list the methods that the User class has that the base Object class does not have…
Note that
methodsis a method for Classes and for Class instances.Here’s the methods that my User class has that are not in the ActiveRecord base class:
Note that the methods created as a result of the (many) has_many relationships defined in the User class are not in the results of the
methodscall.Added Note that :has_many does not add methods directly. Instead, the ActiveRecord machinery uses the Ruby
method_missingandresponds_totechniques to handle method calls on the fly. As a result, the methods are not listed in themethodsmethod result.