Skip to content

Instantly share code, notes, and snippets.

@FioFiyo
Last active April 5, 2016 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FioFiyo/d34f8d1fdb633910e14802827083f384 to your computer and use it in GitHub Desktop.
Save FioFiyo/d34f8d1fdb633910e14802827083f384 to your computer and use it in GitHub Desktop.
Inheritance of animals and using modules to add features on subclasses
require 'pry'
require_relative 'methods.rb'
class Animal
attr_accessor :num_legs, :body
def initialize (num_legs, body = true)
@num_legs = num_legs
@body = body
end
def animal
if (@num_legs == 4 && @body == true)
"I'm an Animal!"
else
"I'm an alien"
end
end
end
#------------------------------------------
class Mammals < Animal
#furry
def initialize (num_legs, body, furr = true)
super(num_legs, body)
@furr = furr
end
def animal
if @num_legs == 3
"Someone chopped it off but i'm still both animal and mammal"
else
super
end
end
end
class Amphibian < Animal
#breathes under water AND on land
def initialize (num_legs, body, multi_breathe = true)
super(num_legs, body)
@multi_breathe = multi_breathe
end
def animal
if (@multi_breathe == true) && (num_legs == 4)
"I can do more breathing underwater too!"
else
"I think I'm not a frog after all"
end
end
end
class Primate < Animal
#has opposable thumb
def initialize (num_legs, body, opp_thumbs = true)
super(num_legs, body)
@opp_thumbs = opp_thumbs
end
def animal
if (num_legs == 2) && (@opp_thumbs == true)
"Let me count your bills with my opposable thumb"
else
"Can't be a monkey no more"
end
end
end
class Frog < Amphibian
#tongue fetch
def initialize (num_legs, body, tongue_fetch)
super(num_legs,body)
@tongue_fetch = tongue_fetch
end
def tongue_fetch
if @tongue_fetch == 'quick'
puts "I can snap that fly in a boogie"
else
puts "My tongue is tiny"
end
end
end
class Bat < Mammals
#sonar hearing
def initialize (num_legs, body,furr, sonar)
super(num_legs, body, furr)
@sonar = sonar
end
def sonarhear
unless @sonar
puts "I'm too old for a bat to hear"
else
puts "I can hear you talking 'bout me a mile away"
end
end
end
class Bird < Mammals
include Birds
attr_reader :wings
def initialize(num_legs, body, wings = true)
super(num_legs, body)
@wings = wings
end
end
class Parrot < Bird
attr_reader :num_legs,:body,:wings
def initialize (num_legs, speech = 'y')
@speech = speech
@num_legs = num_legs
end
def talking
if @speech == 'y' && @num_legs == 1
puts "Give me an accent and I can speak like Arnold Swahdfkshfla"
else
puts " *sing tunes with one leg*"
end
end
end
# class Chimpanzee
# #have the brains
# def braniac
# end
# end
require_relative './animals'
# cat = Mammals.new(5, true, true)
# puts cat.animal
# frog = Amphibian.new(4,true,true)
# puts frog.animal
# monkey = Primate.new(2,true, true)
# puts monkey.animal
# frog = Frog.new(4, true, '')
# frog.tongue_fetch
# batt = Bat.new(2, true, true, true)
# batt.sonarhear
# pepe = Bird.new(2, true,true)
# pepe.flappy_bird
maria = Parrot.new(2, 'y')
maria.talking
module Birds
def flappy_bird
if wings == true
puts "I can fly like a G6!"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment