function_exists
-
We can check if a method exists in Ruby by seeing if an object responds to a message by that method’s name. We do this using the
Object#respond_to?method which takes a single argument using a symbol of the method we’re checking.PHP
function foo() {} $result = function_exists('foo'); var_export($result); // => true $result = function_exists('bar'); var_export($result); // => false
Ruby
def foo; end p respond_to?(:foo) # => true p respond_to?(:bar) # => false
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

