Skip to content

Instantly share code, notes, and snippets.

@cmjaimet
Last active February 20, 2019 19:32
Show Gist options
  • Save cmjaimet/067b8b8359006214d5701202cf705657 to your computer and use it in GitHub Desktop.
Save cmjaimet/067b8b8359006214d5701202cf705657 to your computer and use it in GitHub Desktop.
Minimal ruby class
class Hangman
attr_reader :answer # creates getter method so class property is not accessed directly as data
def initialize()
@answer = get_answer # set the value of the class property
end
def get_answer()
puts "Enter Answer:" # prints a prompt to the screen
gets.chomp.upcase # gets the input from user and converts it to uppercase - convert later to a method to validate format (/[a-zA-Z ]{3,30}/)
end
end
puts Hangman.new.answer # create an object instance of the Hangman class and print the return value from the answer method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment