Answers for "ruby is method"

0

ruby is method defined

# 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)
Posted by: Guest on December-11-2020
0

ruby method

def print_args(arg1,ar2)
	puts arg1
    puts arg2
end
Posted by: Guest on November-28-2020

Browse Popular Code Answers by Language