Does Ruby Have Primitive Data Types?

Unlike some other programming languages (such as JavaScript, Java, C#, etc.), Ruby does not have any primitive data types. In fact, everything in Ruby is an object, as you can see in the following examples:

puts 'foo'.class #=> String
puts 1234.class #=> Integer
puts 0b101.class #=> Integer
puts 0o30071.class #=> Integer
puts 0x4d2.class #=> Integer
puts :bar.class #=> Symbol
puts true.class #=> TrueClass
puts false.class #=> FalseClass
puts 12.34.class #=> Float
puts 1.234e2.class #=> Float
puts nil.class #=> NilClass

Some other programming languages use primitive data types mainly for performance purposes (as creating objects has an additional overhead comparatively). However, Ruby opts for a purely object-oriented design, to promote ease-of-learning and familiarity (as objects are used throughout Ruby, and thus, rules applying to objects apply to all of Ruby).

Hope you found this post useful. It was published . Please show your love and support by sharing this post.