Get all variables defined through `attr_accessor` without overriding `attr_accessor`

前端 未结 2 1217
无人共我
无人共我 2021-01-04 23:11

I am setting some trace code on my program, and would like to know which methods are defined through attr_accessor. Using TracePoint, I can detect

2条回答
  •  日久生厌
    2021-01-04 23:17

    you can use obj.methods() to find all the methods available on the instance (inc methods from superclasses), and obj.methods(false) to get only the method defined on current singleton object. I'm not sure its possible to detect if these methods where created via attr_accessor though

提交回复
热议问题