Skip to content

Instantly share code, notes, and snippets.

@caioertai
Created April 21, 2022 22:57
Show Gist options
  • Save caioertai/149ad833fea010aae210bac1ce38ecce to your computer and use it in GitHub Desktop.
Save caioertai/149ad833fea010aae210bac1ce38ecce to your computer and use it in GitHub Desktop.
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
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
require_relative "animal"
class Lion < Animal
def talk
"#{name} roars"
end
def eat(food)
"#{super(food)} Law of the Jungle!"
end
end
require_relative "animal"
class Meerkat < Animal
def talk
"#{name} barks"
end
end
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