Code Editor
Learn
Introduction to Ruby

Variables

One of the most basic concepts in computer programming is the variable. You can think of a variable as a word or name that grasps a single value. For example, let's say you needed the number 25 from our last example, but you're not going to use it right away. You can set a variable, say my_num, to grasp the value 25 and hang onto it for later use, like this:

my_num = 25

Declaring variables in Ruby is easy: you just write out a name like my_num, use = to assign it a value, and you're done! If you need to change a variable, no sweat: just type it again and hit = to assign it a new value.

Report a Bug
If you see a bug or any other issue with this page, please report it here.