Convert PHP code into Ruby!
RSS icon Email icon Home icon
  • 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_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