Data Types in Ruby
Learn about the different data types in Ruby.
Data types
In the previous chapters, we figured out how to join two strings with "+"
. Also, we know now that we can multiply a string by a number. While experimenting, we found that there are at least two types of data: strings and numbers, also known as integers. We also learned that a number itself, written in quotation marks, is a string. Let’s see how Ruby understands what a number and what a string is:
Ruby
# Experimenting to see how Ruby understands a number and a stringputs "blabla".classputs "123".classputs 123.class
The documentation says that everything is an object in Ruby. So, the result of any operation is an object. Every object implements a method called a class
. The expression “implements a ...