Last active
September 23, 2015 10:45
-
-
Save kasiapryczek/760b5e71c6c6e8705d71 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 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 |
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 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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great.