Type of an object in ruby

Last Updated On Tuesday 25th Jan 2022

ruby check type

ruby object type

The proper way to determine the type of an object, is to call object.class.

Object.class method

	first = "Hello World"
second = 21
puts "The class of first is #{first.class}"
puts "The class of second is #{second.class}"

ruby type

	The class of first is String
The class of second is Integer

ruby type of

This method is defined in the Object class of Ruby’s library and sorely used for checking the class of a particular object or instance.


ruby type of object

	first = "Hello World"
second = 21

if (first.is_a?(String) == true)
    puts "First is of String class"

if (second.is_a?(Integer) == true)
    puts "Second is of Integer class"
	First is of String class
Second is of Integer class