-
-
Save fujin/1685125 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
module Scoreable | |
attr_accessor :score | |
def increment | |
@score += 1 | |
end | |
def decrement | |
@score -= 1 | |
end | |
end | |
class Kid | |
include Scoreable | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
@score = 0 | |
end | |
def to_s | |
"#{name}'s score is #{score}" | |
end | |
end | |
kids = %w[alice josie parker].inject({}) do |hash,kid| | |
hash[kid] = Kid.new(kid.capitalize) | |
hash | |
end.each do |name, kid| | |
puts name | |
puts kid | |
kid.increment | |
puts kid | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment