-
-
Save amcaplan/47ed2d92e8f95a82e99b to your computer and use it in GitHub Desktop.
Animals, round 1
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
class Animal | |
@@animals = [] | |
@@legs = 4 | |
def initialize(args={}) | |
@@animals << self | |
after_initialize(args) | |
end | |
def after_initialize(args) | |
end | |
def legs | |
@@legs | |
end | |
def self.all | |
@@animals | |
end | |
end | |
class Octopus < Animal | |
@@octopi = [] | |
@@legs = 8 | |
def after_initialize(args={}) | |
@@octopi << self | |
end | |
def self.all | |
@@octopi | |
end | |
end | |
class Llama < Animal | |
@@llamas = [] | |
def after_initialize(args={}) | |
@@llamas << self | |
end | |
def self.all | |
@@llamas | |
end | |
end | |
Llama.new.legs # => 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment