Skip to content

Instantly share code, notes, and snippets.

@rayning0
Last active December 24, 2015 08:39
Show Gist options
  • Select an option

  • Save rayning0/6771721 to your computer and use it in GitHub Desktop.

Select an option

Save rayning0/6771721 to your computer and use it in GitHub Desktop.
Deli Counter
def take_a_number(katz, name)
katz << name
return katz.size
end
def line(katz)
print "The line is currently:"
katz.each_with_index do |name, i|
print " #{i + 1}. #{name}"
end
puts
end
def now_serving(katz)
puts "Currently serving #{katz[0]}"
katz.shift
end
katz_deli = []
puts take_a_number(katz_deli, "Ada") #=> "1"
puts take_a_number(katz_deli, "Grace") #=> "2"
puts take_a_number(katz_deli, "Kent") #=> "3"
line(katz_deli) #=> "The line is currently: 1. Ada 2. Grace 3. Kent"
now_serving(katz_deli) #=> "Currently serving Ada"
line(katz_deli) #=> "The line is currently: 1. Grace 2. Kent"
p take_a_number(katz_deli, "Matz") #=> "3"
line(katz_deli) #=> "The line is currently: 1. Grace 2. Kent 3. Matz"
now_serving(katz_deli) #=> "Currently serving Grace"
line(katz_deli) #=> "1. Kent 2. Matz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment