-
-
Save amcaplan/a83d917476be44daaeff to your computer and use it in GitHub Desktop.
Animals, round 3
This file contains 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
# 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