is_numeric

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

    PHP

    $number = 2;
    $result = is_numeric($number);
    var_export($result);
    // => true
     
    $number = 1.2;
    $result = is_numeric($number);
    var_export($result);
    // => true

    Ruby

    number = 2
    p number.is_a?(Numeric)
    # => true
     
    number = 1.2
    p number.is_a?(Numeric)
    # => true

    see also

is_null is_object

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.