-
-
Save anonymous/1432172 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
class StudyingStudents | |
def initialize | |
print "\n\nHow many subjects are we talking about? Enter an integer: " | |
@quantity = $stdin.gets.chomp.to_i | |
print "\n\nWhat type of subject are we talking about? Enter a singular string: " | |
@subject = $stdin.gets.chomp.downcase | |
@subject_plural = @subject + "s" | |
print "\n\nWhat is the exact location in question? Enter a brief string: " | |
@location = $stdin.gets.chomp.downcase | |
end | |
def is_empty? | |
@quantity.zero? # == 0? | |
end | |
def start_staring # action begins here | |
puts keep_staring(", are furiously studying at the #{@location}. ") + one_gets_frustrated + keep_staring(" remain at the #{@location}") | |
end | |
def keep_staring(context="") # output starts here ... main stanza | |
"#{(@quantity > 0)? "#{@quantity}" : 'No more' } " "#{(@quantity == 1)? @subject : @subject_plural}" + context | |
end | |
def one_gets_frustrated | |
@quantity -= 1 | |
"One leaves to go home, bake a rhubarb pie, and call it a day. " | |
end | |
end | |
lair = StudyingStudents.new | |
lair.start_staring until lair.is_empty? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment