Exploring types of variables
Variables in Ruby have the same utility as in other programming languages: they are mutable containers for values. Simply put, variables are used to save values for later usage. These values may change over time, or even change the type of data they contain.
Just like with PHP, Ruby is dynamically typed (or duck typing), which means that the interpreter infers what type of data we are handling at runtime. We don’t need to tell Ruby or PHP that a variable is either a string, a number, or a Boolean. One difference with PHP, however, is that in later versions of PHP, you can specify what type of data to use, especially in object-oriented PHP. However, even with this “enhancement,” the majority of the language remains duck-typed.
How does this affect us as developers? Well, let’s take a look at a simple example. First, open an IRS. Type the following command:
irb
As we saw previously, once we type this command, the shell...