How to list all methods for an object in Ruby?

后端 未结 8 1935
北荒
北荒 2020-12-07 08:44

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:



        
8条回答
  •  甜味超标
    2020-12-07 09:25

    Suppose User has_many Posts:

    u = User.first
    u.posts.methods
    u.posts.methods - Object.methods
    

提交回复
热议问题