I have two methods defined in my ruby file.
def is_mandatory(string)
puts xyz
end
def is_alphabets(string)
puts abc
end
An
All previous solutions with send
are fine but it is recommended to use public_send instead (otherwise you can be calling private methods).
Example:
'string'.public_send(:size)
=> 6
You can also add hash to send parameters to the method.
send("method_name", "abc", {add more parameters in this hash})
Try using "send".
methods.each do |method|
self.send(method, "abc")
end
Best way is probably:
methods.each { |methodName| send(methodName, 'abc') }
See Object#send