Created
April 21, 2022 22:57
-
-
Save caioertai/149ad833fea010aae210bac1ce38ecce to your computer and use it in GitHub Desktop.
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 | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
def self.phyla | |
["phyla1", "phyla2", "phyla3", "phyla4"] | |
end | |
def eat(food) | |
"#{name} eats a #{food}." | |
end | |
end |
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
require_relative "lion" | |
require_relative "meerkat" | |
require_relative "warthog" | |
animals = [ | |
Lion.new("Simba"), | |
Meerkat.new("Timon"), | |
Warthog.new("Pumba"), | |
Lion.new("Nala") | |
] | |
animals.each do |animal| | |
puts animal.talk | |
end | |
animals.each do |animal| | |
puts animal.eat("meat") | |
end |
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
require_relative "animal" | |
class Lion < Animal | |
def talk | |
"#{name} roars" | |
end | |
def eat(food) | |
"#{super(food)} Law of the Jungle!" | |
end | |
end |
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
require_relative "animal" | |
class Meerkat < Animal | |
def talk | |
"#{name} barks" | |
end | |
end |
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
require_relative "animal" | |
class Warthog < Animal | |
def talk | |
"#{name} grunts" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment