1

Is there a class method to check if there is a certain instance method for that class? Something like respond_to? that is a class method.

sawa
  • 165,429
  • 45
  • 277
  • 381

2 Answers2

4

Yes, you can use

 method_defined?

,which is class method to check whether particular class has instance method defined or not. Following link will explain you more

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

Community
  • 1
  • 1
maximus ツ
  • 7,949
  • 3
  • 25
  • 54
0

Use method_defined? on Class

Ex: Array.method_defined? :sort

Prem
  • 5,844
  • 3
  • 25
  • 23