Skip to content

Instantly share code, notes, and snippets.

/t.rb

Created December 5, 2011 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1432172 to your computer and use it in GitHub Desktop.
Save anonymous/1432172 to your computer and use it in GitHub Desktop.
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