Last active
July 26, 2016 14:07
-
-
Save nelantone/ec75351e247366a3016c2b026e768f31 to your computer and use it in GitHub Desktop.
3.4
This file contains hidden or 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, hungry) | |
@color = color | |
@breed = breed | |
@hungry = true | |
end | |
def feed(food) | |
puts 'Mmmm, ' + food + '!' | |
@hungry = false | |
end | |
def hungry? | |
if @hungry == true | |
puts 'I\'m hungry' | |
else | |
puts 'I\'m full!' | |
end | |
@hungry | |
end | |
def speak | |
puts 'Meow!' | |
end | |
end | |
Kitty = Cat.new('grey', 'what?','') | |
puts 'Let\'s inspect our new cat:' | |
puts Kitty.inspect | |
puts 'What class our new cat beling to?' | |
puts Kitty.class | |
puts 'It\'s our new cat an object?' | |
puts Kitty.is_a?(Object) | |
puts 'What color it\'s our cat?' | |
puts Kitty.color | |
puts 'Let\'s give our new cat a name' | |
Kitty.name = 'Fufu' | |
puts Kitty.name | |
puts 'Is our cat hungry now?' | |
Kitty.hungry? | |
puts 'Let\'s feed our cat' | |
Kitty.feed('Wiskas') | |
puts 'It is our cat hungry now?' | |
Kitty.hungry? | |
puts 'Our cat can make noise' | |
puts Kitty.speak |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment