0 Replies - 1296 Views - Last Post: 10 February 2010 - 09:09 PM

#1 Skaggles   User is offline

  • THE PEN IS MIGHTIER
  • member icon





Reputation: 255
  • View blog
  • Posts: 641
  • Joined: 01-March 09

Get Confirmation

Posted 10 February 2010 - 09:09 PM

Description: This method returns True or False depending on the users respone. It assumes you are asking the user a yes/no question, but can be easily changed to fit other user queries. Example of use: if user_confirms? "Do you like pie?" print "Yay, me too!" else print "Boo." endA very simple method that will ask the user for a Yes or No response.
def user_confirms?(question)
  while true            # Loop until response is given
    print question      # Print the question
    response = gets     # Get the users response
    case response
    when /^[yY]/        # If the user said Yes
      return true       # return true
    when /^[nN]/        # If the user said No
      return false      # Return false
    end
  end
end


Is This A Good Question/Topic? 0
  • +

Page 1 of 1