Skip to content

Instantly share code, notes, and snippets.

@RobertoBarros
Created October 30, 2025 21:03
Show Gist options
  • Select an option

  • Save RobertoBarros/d8862206311b223c964daa63d95b8983 to your computer and use it in GitHub Desktop.

Select an option

Save RobertoBarros/d8862206311b223c964daa63d95b8983 to your computer and use it in GitHub Desktop.
Batch 2166 - Livecode OOP
class Animal
attr_reader :name
def initialize(name)
@name = name
end
def self.phyla
%w[Porifera Cnidaria Platyhelminthes Nematoda Annelida Arthropoda Mollusca Echinodermata Chordata]
end
def eat(food)
"The #{@name} eats #{food}."
end
end
#######################################
class Lion < Animal
def talk
"#{@name} roars"
end
def eat(food)
"#{super} Law of the jungle!"
end
end
#######################################
class Meerkat < Animal
def talk
"#{@name} bark"
end
end
######################################
class Warthog < Animal
def talk
"#{@name} grunt"
end
end
#########################################
#### Using our Classes:
simba = Lion.new("Simba")
timao = Meerkat.new("Timão")
pumba = Warthog.new("Pumba")
nala = Lion.new("Nala")
animals = [simba, timao, pumba, nala]
animals.each do |a|
puts a.talk
end
puts Animal.phyla
puts timao.eat("escorpiao")
puts simba.eat("gazela")
puts pumba.eat("planta")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment