is_a

  • We can check if an object instance is of a certain class in Ruby using the Object.is_a? method.

    PHP

    class Car {}
     
    $bmw = new Car;
    $result = is_a($bmw, "Car");
    var_export($result);
    // => true

    Ruby

    class Car; end
     
    bmw = Car.new
    p bmw.is_a?(Car)
    # => true

    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.