Created
June 15, 2009 21:48
-
-
Save anonymous/130370 to your computer and use it in GitHub Desktop.
This file contains 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
# ruby beginner elevator program | |
# elevator functions | |
class Building | |
def elevator | |
puts "floor " + rand(10).to_s + " is where the elevator user is at, going to that floor" | |
end | |
end | |
my_building = Building.new | |
my_building.elevator | |
# this happens when person is in elevator | |
# original version of this code written by calvin stephens | |
# re-factored if statement version below by my Ruby mentor | |
puts "what floor of the building do you want?" | |
choice = gets.chomp.to_i | |
floors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
if choice < 1 || choice > 10 | |
puts "the elevator doesn't go to floor #{choice}!" | |
else | |
puts "going to floor #{floors[choice-1]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment