Skip to content

Instantly share code, notes, and snippets.

@amcaplan
Last active August 29, 2015 14:01
Show Gist options
  • Save amcaplan/a83d917476be44daaeff to your computer and use it in GitHub Desktop.
Save amcaplan/a83d917476be44daaeff to your computer and use it in GitHub Desktop.
Animals, round 3
# IRRELEVANT CODE EXCISED
class Animal
@animals = []
def self.animals
@animals
end
def initialize(args={})
Animal.animals << self
after_initialize(args)
end
def after_initialize(args)
end
def self.all
self.animals
end
end
class Lion < Animal
@animals = []
def after_initialize(args)
self.class.animals << self
end
end
Lion.new
Animal.all # => [#<Lion:0x0000010187de60>]
Animal.all.object_id # => 2160486800
Lion.all # [#<Lion:0x0000010187de60>]
Lion.all.object_id # => 2160342160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment