OneBite.Dev - Coding blog in a bite size

assign multiple variables in Ruby

Code snippet on how to assign multiple variables in Ruby

a, b, c = 10, 20, 30

This code assigns the values 10, 20, and 30, to the variables a, b and c respectively. The code can be broken down into 3 parts. The first part is the variables. The code starts with the variables a, b and c on the left side of the equals sign. These are the variables that are being set to the values on the right side of the equation. The second part is the equals sign =. This sign indicates that each of the variables on the left is being assigned to the values on the right. The third part is the values 10, 20, and 30. These are the values that are being assigned to the variables on the left. This code assigns each variable on the left a different value on the right, but the same values could be used for multiple variables if the same values are desired.

ruby