How do I inspect the methods of a Ruby object?

前端 未结 3 1643
Happy的楠姐
Happy的楠姐 2021-02-02 12:06

I am wondering if there is a Ruby method call that shows only the methods defined by the Ruby object it\'s called from, as opposed to all the methods defined by its ancestor cla

3条回答
  •  余生分开走
    2021-02-02 12:30

    I'm partial to obj.methods.sort but some of the other answers are better in certain cases as they describe

    You can also use obj.methods.sort.grep /foo/ to find method names matching the regexp. This is helpful when you have an idea of what you're looking for.

提交回复
热议问题