Created
September 30, 2013 21:04
-
-
Save davidbella/6770241 to your computer and use it in GitHub Desktop.
Ruby: Deli line - practice using arrays and collections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deli_line = [] | |
def take_a_number(deli_line, name) | |
deli_line << name | |
deli_line.count | |
end | |
p take_a_number(deli_line, "David") | |
p take_a_number(deli_line, "Kyle") | |
def line(deli_line) | |
pretty_line = deli_line.collect.with_index do |name, index| | |
"#{index + 1}. #{name}" | |
end | |
"The line is currently: " + pretty_line.join(' ') | |
end | |
p line(deli_line) | |
def now_serving(deli_line) | |
"Currently serving " + deli_line.shift | |
end | |
p now_serving(deli_line) | |
p line(deli_line) | |
p take_a_number(deli_line, "Greg") | |
p take_a_number(deli_line, "Rosie") | |
p line(deli_line) | |
p now_serving(deli_line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment