PHP to Ruby
Convert PHP code into Ruby!
-
gettype
Posted on August 21st, 2009 No commentsThe 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 No commentsThe 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


