Skip to content

Instantly share code, notes, and snippets.

@ahimmelstoss
Created October 1, 2013 01:14
Show Gist options
  • Save ahimmelstoss/6772627 to your computer and use it in GitHub Desktop.
Save ahimmelstoss/6772627 to your computer and use it in GitHub Desktop.
amandas_deli = []
def take_a_number(amandas_deli, customer)
amandas_deli << customer
puts "#{customer}, you are number #{amandas_deli.count} in line."
#counts number of elements in array
end
def line(amandas_deli)
puts "The line is currently:"
amandas_deli.each_with_index {|customer, i| puts "#{i+1}. #{customer}"}
end
def now_serving(amandas_deli)
puts "Currently serving #{amandas_deli.shift}."
#shift removes first element and returns it, shifting all elements down.
end
take_a_number(amandas_deli, "Ada") #Ada, you are number 1 in line.
take_a_number(amandas_deli, "Grace") #Grace, you are number 2 in line.
take_a_number(amandas_deli, "Kent") #Kent, you are number 3 in line.
line(amandas_deli) #=> "The line is currently: 1. Ada 2. Grace 3. Kent"
now_serving(amandas_deli) #=> "Currently serving Ada"
line(amandas_deli) #=> "The line is currently: 1. Grace 2. Kent"
take_a_number(amandas_deli, "Matz") #=> "3"
line(amandas_deli) #=> "The line is currently: 1. Grace 2. Kent 3. Matz"
now_serving(amandas_deli) #=> "Currently serving Grace"
line(amandas_deli) #=> "1. Kent 2. Matz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment