Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 795 Bytes

variables.md

File metadata and controls

42 lines (33 loc) · 795 Bytes

Variables

What is a variable?

  • A variable as a word used to store a value (information) in programs.
  • To assign a value to a variable, use '=' operator. The name of variable in the left and value of this variable in the right.

Examples:

welcome = 'Welcome to Ruby Programming'
one     = 1
price   = 10.25

In above examples, welcome, one and price are variables. In there:

  • welcome has value is 'Welcome to Ruby Programming'
  • one has value is 1
  • price has value is 10.25

Now we can reference to variables like that:

irb:001> welcome
=> "Welcome to Ruby Programming"
irb:002> price
=> 10.25

Try others example in irb:

# string
hello = "Hello World!"

# number
money = 1000
price = 100.25

# booleans
true_val  = true
false_val = false