Skip to content

Instantly share code, notes, and snippets.

@kasiapryczek
Last active September 23, 2015 10:45
Show Gist options
  • Save kasiapryczek/760b5e71c6c6e8705d71 to your computer and use it in GitHub Desktop.
Save kasiapryczek/760b5e71c6c6e8705d71 to your computer and use it in GitHub Desktop.
class Cat
attr_reader :color, :breed
attr_accessor :name
def initialize(color, breed)
@color = color
@breed = breed
@hungry = true
end
def feed(food)
puts "Mmmm " + food + "!"
@hungry = false
end
def hungry?
if @hungry
puts "I am hungry"
else
puts "I am full!"
end
@hungry
end
def speak
puts "Meow!"
end
end
kitty = Cat.new("grey", "persian")
puts "Let\'s inspect our new cat"
puts kitty.inspect
puts "What class does your new cat belong to?"
puts kitty.class
puts "is our new cat an object?"
puts kitty.is_a?(Object)
puts "What colour is our cat?"
puts kitty.color
puts "Let\'s give our Cat a name"
kitty.name = "betsy"
puts kitty.name
puts "Is our Cat hungry now?"
puts kitty.hungry?
puts "Let\'s feed our Cat"
puts kitty.feed("tuna")
puts "Is our Cat hungry now?"
puts kitty.hungry?
puts "Our Cat can make noise"
puts kitty.speak
class Pet
attr_reader :color, :breed
attr_accessor :name
def initialize(color, breed)
@color = color
@breed = breed
@hungry = true
end
def feed(food)
puts "Mmmm, " + food + "!"
@hungry = false
end
def hungry?
if @hungry
puts "I\'m hungry!"
else
puts "I\'m full!"
end
@hungry
end
end
class Dog < Pet
def speak
puts "Woof!"
end
end
puppy = Dog.new("Black", "German Sheppard")
puts "I say..."
puppy.speak
puts "Because I am a..."
puts puppy.breed
puts "My color is..."
puts puppy.color
puts "and..."
puts puppy.hungry?
@dogweather
Copy link

Great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment