Ruby Variables
# Ruby variables
a = 1
puts a
b = "Hello"
puts b
# Types of variables
local variables
instance variables
global variables
constants
# Global variables
# Globals have a $ in front and are typically written in lower case
# You don't use it very often
# Constants
# WRITTEN IN ALL UPPER CASE
# Local Variable
# Typically written in lower case and underscored - lower case
# You can access any whee else just inside de function ex: def order
# Instance Variable
# local vs instance (this is available trought out your class - it can be access inside order) - lower case
$toppings = false # $toppings - Global variables
class Burger # class name use camel the first letter is uppercase
AVAILABLE_TOPPINGS = ["lettuce", "tomato", "onion", "pickles", "relish"] # AVAILABLE_TOPPINGS - Constants
attr_reader :options
def initialize
@toppings = [] # @toppings - instance variables
end
def order
print "How many burgers would you like? "
number = get.chomp # number - local variable
puts "#{number} burgers coming right up."
end
end
burger = Burger.new("lettuce")
burger.order
# Control Flow
a = 3
if a == 1
puts "a is 1"
elsif a == 2
puts "a is 2"
else
puts " I don't know the value of a"
end
-------
# case statement
case a
when 1
puts "a is 1"
when 2
puts "a is 2"
else
puts " I don't know the value of a"
end