Advertisement
Guest User

Untitled

a guest
Dec 4th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.08 KB | None | 0 0
  1.  
  2. class StudyingStudents
  3.   def initialize
  4.     print "\n\nHow many subjects are we talking about? Enter an integer: "
  5.     @quantity = $stdin.gets.chomp.to_i
  6.     print "\n\nWhat type of subject are we talking about? Enter a singular string: "
  7.     @subject = $stdin.gets.chomp.downcase
  8.     @subject_plural = @subject + "s"
  9.     print "\n\nWhat is the exact location in question? Enter a brief string: "
  10.     @location = $stdin.gets.chomp.downcase
  11.   end
  12.  
  13.   def is_empty?
  14.     @quantity.zero? # == 0?
  15.   end
  16.  
  17.   def start_staring # action begins here
  18.      puts keep_staring("are furiously studying at the #{@location}. ") + one_gets_frustrated + keep_staring(" remain at the #{@location}")
  19.   end
  20.  
  21.   def keep_staring(context="") # output starts here ... main stanza
  22.     "#{(@quantity > 0)? @quantity.to_s : 'No more' } " "#{(@quantity == 1)?  @subject : @subject_plural}" + context
  23.   end
  24.  
  25.   def one_gets_frustrated
  26.     @quantity -= 1
  27.     print "One leaves to go home, bake a rhubarb pie, and call it a day. "
  28.   end
  29. end
  30.  
  31. lair = StudyingStudents.new
  32. lair.start_staring until lair.is_empty?
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement