Zoonk icon

How to declare variables in Ruby

Created by Will Ceolin
Created on Feb 10, 20 - Updated on Mar 8, 20

Variables are values you can declare to use later. For example, let's say we want to save someone's name in our program. We can do it by declaring a new variable:

name = "Nikola Tesla"

In the example above, we called our variable and assigned a "Nikola Tesla" value to it. You can give any name you want to your variable, but it's useful when you name it as something other people can easily understand your code.

For example, when you write a generic variable like this:

var = "Google"

Other people won't know what your variable is referring to. However, if you give your variable a descriptive name, then it becomes easier for other developers to read your code:

brand = "Google"

When we're calling that or variable, then we'll know they refer to a brand and a name, respectively. There are many ways you can use variables, and they can have different types. But we'll cover those topics in the next lessons.