Are there primitive types in Ruby?

emily picture emily · Sep 13, 2013 · Viewed 15k times · Source

I'm a Java developer who is just starting to learn Ruby. Does Ruby have any primitive types? I can't seem to find a list of them. If not, why?

Answer

dbyrne picture dbyrne · Sep 13, 2013

A core principle of Ruby is that all data should be represented as objects. Other languages such as Smalltalk follow a similar paradigm.

The benefit of this design is that it makes Ruby more elegant and easier to learn. The rules applying to objects are consistently applied to all of Ruby.

For instance, when beginners are first learning Java, the difference between the primitive type int and the wrapper class Integer can be confusing. This confusion is exacerbated by the sometimes confusing implicit conversions between the two via autoboxing.

So why would languages like Java or C# bother with primitive types? The answer is performance. Creating objects incurs additional overhead when compared with primitives.