Ruby Is Method Defined

[Solved] Ruby Is Method Defined | Ruby - Code Explorer | yomemimo.com
Question : ruby is method defined

Answered by : braden

# respond_to?(symbol, include_all=false) works well for testing if an object has a method defined
# .try() will not handle methods that have parameters, respond_to? does handle those methods
if my_obj.respond_to?(:my_method)	my_obj.my_method(arg1, arg2)
end
# You can also try instance_methods(false).include?(symbol) for class objects
my_class_obj.instance_methods(false).include?(:my_method)

Source : https://stackoverflow.com/questions/4865506/checking-if-a-method-is-defined-on-the-class | Last Update : Fri, 18 Dec 20

Answers related to ruby is method defined

Code Explorer Popular Question For Ruby