Given a class, see if instance has method (Ruby)

前端 未结 12 1829

I know in Ruby that I can use respond_to? to check if an object has a certain method.

But, given the class, how can I check if the instance has a certai

12条回答
  •  無奈伤痛
    2020-12-12 12:51

    klass.instance_methods.include :method_name or "method_name", depending on the Ruby version I think.

提交回复
热议问题