method_exists

  • Calling a method in Ruby is often referred to as “sending a message” to an object. Ruby methods reflect this idea and terminology. We check if a method exist by checking if an object “responds to” a certain message using Object#respond_to?.

    PHP

    class Car {
      public function drive() {}
    }
    $car = new Car;
    $exists = method_exists($car, 'drive');
    var_export($exists);
    // => true

    Ruby

    class Car
      def drive; end
    end
     
    car = Car.new
    p respond_to?(:drive)
    # => true

    see also

metaphone mkdir

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.