Skip to content

Instantly share code, notes, and snippets.

@fujin
Forked from pguth66/gist:1685108
Created January 26, 2012 21:11
Show Gist options
  • Save fujin/1685125 to your computer and use it in GitHub Desktop.
Save fujin/1685125 to your computer and use it in GitHub Desktop.
KIDS
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