Created
January 26, 2012 21:06
-
-
Save pguth66/1685108 to your computer and use it in GitHub Desktop.
KIDS
This file contains hidden or 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 Kid | |
def initialize(name) | |
@name = name | |
@score = 0 | |
end | |
def getapoint | |
@score += 1 | |
end | |
def useapoint | |
@score -= 1 | |
end | |
def printScore | |
puts @name + "'s score is " + @score.to_s | |
end | |
attr_reader :score, :name | |
end | |
kids = { | |
'Alice' => Kid.new("Alice"), | |
'Josie' => Kid.new("Josie"), | |
'Parker' => Kid.new("Parker") | |
} | |
kids.each do |name, kid| | |
kid.printScore | |
end | |
kids["Alice"].getapoint | |
kids["Alice"].printScore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment