Reader small image

You're reading from  From PHP to Ruby on Rails

Product typeBook
Published inDec 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781804610091
Edition1st Edition
Languages
Right arrow
Author (1)
Bernard Pineda
Bernard Pineda
author image
Bernard Pineda

Bernard Pineda is a seasoned developer with 20 years of web development experience. Proficient in PHP, Ruby, Python, and other backend technologies, he has taught PHP and PHP-based frameworks through video courses on platforms like LinkedIn Learning. His extensive work with Ruby and Ruby on Rails, along with curiosity in frontend development and game development, bring a diverse perspective to this book. Currently working as a Site Reliability Engineer in Silicon Valley, Bernard is always seeking new adventures.
Read more about Bernard Pineda

Right arrow

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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
From PHP to Ruby on Rails
Published in: Dec 2023Publisher: PacktISBN-13: 9781804610091

Author (1)

author image
Bernard Pineda

Bernard Pineda is a seasoned developer with 20 years of web development experience. Proficient in PHP, Ruby, Python, and other backend technologies, he has taught PHP and PHP-based frameworks through video courses on platforms like LinkedIn Learning. His extensive work with Ruby and Ruby on Rails, along with curiosity in frontend development and game development, bring a diverse perspective to this book. Currently working as a Site Reliability Engineer in Silicon Valley, Bernard is always seeking new adventures.
Read more about Bernard Pineda