How to Check the Data Type of a Variable in Ruby
What is Ruby?
The Ruby programming language is free and open source. It is both object-oriented and interpretive. Yukihiro Matsumoto invented Ruby. Ruby’s founder referred to it as the jewel of programming languages because it was named after a gemstone. Here, we’ll talk about the various Ruby commands.
The following criteria were taken into account during the development of Ruby:
- Simplicity
- Extensiveness
- Completeness
- Portability
Most UNIX-based platforms support Ruby. Ruby was primarily developed on Linux. Common platforms like Windows, DOS, macOS, etc., are all compatible with Ruby.
1. Check integer datatype in Ruby
employees = {'Ahmad' => 9500, 'Irfan' => 6700, 'Ali' => 9700}array=[1,2,3,4,5];puts 1.class
2. Check float datatype in Ruby
employees = {'Ahmad' => 9500, 'Irfan' => 6700, 'Ali' => 9700}array=[1,2,3,4,5];puts 1.0.class
3. Check string datatype in Ruby
employees = {'Ahmad' => 9500, 'Irfan' => 6700, 'Ali' => 9700}array=[1,2,3,4,5];puts 'str'.class
4. Check boolean variable datatype in Ruby
employees = {'Ahmad' => 9500, 'Irfan' => 6700, 'Ali' => 9700}array=[1,2,3,4,5];puts false.classputs true.class
5. Check Hash datatype in Ruby
employees = {'Ahmad' => 9500, 'Irfan' => 6700, 'Ali' => 9700}array=[1,2,3,4,5];puts employees.class
6. Check Array datatype in Ruby
employees = {'Ahmad' => 9500, 'Irfan' => 6700, 'Ali' => 9700}array=[1,2,3,4,5];puts array.class
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved