Skip to content

Instantly share code, notes, and snippets.

@ashleygwilliams
Created November 26, 2013 20:08
Show Gist options
  • Save ashleygwilliams/7665277 to your computer and use it in GitHub Desktop.
Save ashleygwilliams/7665277 to your computer and use it in GitHub Desktop.
class Woodchuck
attr_accessor :chuck_count
@@woodchuck_count = 0
WOODCHUCKS = []
def initialize
@chuck_count = 0
@@woodchuck_count += 1
WOODCHUCKS << self
end
def chuck_wood
@chuck_count += 1
end
def self.woodchuck_count
@@woodchuck_count
end
end
Woodchuck.new
Woodchuck.new
Woodchuck.new
Woodchuck.new
Woodchuck::WOODCHUCKS.each do |woodchuck|
woodchuck.chuck_wood
end
puts Woodchuck::WOODCHUCKS.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment