How to list all methods for an object in Ruby?

后端 未结 8 1929
北荒
北荒 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:21

    You can do

    current_user.methods
    

    For better listing

    puts "\n\current_user.methods : "+ current_user.methods.sort.join("\n").to_s+"\n\n"
    

提交回复
热议问题