Convert PHP code into Ruby!
RSS icon Email icon Home icon
  • is_long

    Posted on August 24th, 2009 RubyLove No comments

    The is_long() function in PHP is simply an alias of is_int() - for full details see the is_int() function.

  • gettype

    Posted on August 21st, 2009 RubyLove No comments

    The gettype() function in PHP returns the type of a variable.

    PHP

    echo gettype(true);
    // => boolean

    Ruby

    puts true.class;
    # => TrueClass
  • is_real

    Posted on August 18th, 2009 RubyLove No comments

    The is_real() function in PHP is simply an alias of is_float() - for full details see the is_float() function.

  • is_object

    Posted on August 15th, 2009 RubyLove No comments

    The is_object() function allows you to check if a particular variable is an object.

    PHP

    $obj = new stdClass();
    var_dump( is_object($obj) );
    // => true

    In Ruby we can check if a variable is an object by using the Object#is_a? method - however this will always return true as with Ruby everything (almost) is an object.

    Ruby

    puts "Hello World".is_a?(Object);
    # => true
  • is_string

    Posted on August 12th, 2009 RubyLove No comments

    The is_string() function allows you to check if a particular variable is a string (type).

    PHP

    $string1 = 'Hello World';
    var_dump( is_string($string1) );
    // => true

    Ruby

    string1 = 'Hello World';
    puts string1.is_a?(String);
    # => true
  • is_numeric

    Posted on August 8th, 2009 RubyLove 3 comments

    The is_numeric() function allows you to check if a particular variable is a numeric string. Numeric strings can consist of a sign, any number of digits, a decimal part and an exponential part.

    PHP

    $my_string = '+1.998';
    var_dump( is_numeric($string1) );
    // => true

    Ruby

    def is_numeric?(num)
        true if Float(num) rescue false;
    end
     
    my_string = '+1.985';
    puts is_numeric?(my_string);
    # => true
  • is_int

    Posted on August 4th, 2009 RubyLove No comments

    The is_int() function allows you to check if a particular variable is an integer (type).

    PHP

    $number = 9.5;
    var_dump( is_int($number) );
    // => false

    Ruby

    number = 9.5;
    puts number.is_a?(Integer);
    # => false
  • is_bool

    Posted on August 1st, 2009 RubyLove No comments

    The is_bool() function allows you to check if a particular variable is a boolean (type).

    PHP

    $my_variable = 1;
    var_dump( is_bool($my_variable) );
    // => false

    Ruby

     my_variable = 1;
    puts my_variable.is_a?(FalseClass) || my_variable.is_a?(TrueClass)
    # => false
  • is_float

    Posted on July 29th, 2009 RubyLove No comments

    The is_float() function allows you to check if a particular variable is a float (type).

    PHP

    $number = 6.5;
    var_dump( is_float($number) );
    // => true

    Ruby

    number = 6.5;
    puts number.is_a?(Float);
    # => true