is_bool

  • We can check if a variable is a boolean in Ruby using Object#is_a?.

    PHP

    $myVar = true;
    $result = is_bool($myVar);
    var_export($result);
    // => true

    Ruby

    my_var = true
    p my_var.is_a?(TrueClass) || my_var.is_a?(FalseClass)
    # => true

    see also

is_array is_dir

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.