Skip to content

Instantly share code, notes, and snippets.

@radavis
Created August 27, 2013 20:21
Show Gist options
  • Select an option

  • Save radavis/6358648 to your computer and use it in GitHub Desktop.

Select an option

Save radavis/6358648 to your computer and use it in GitHub Desktop.
class Animal
attr_reader :name
def initialize(name)
@name = name
end
def eat
3.times { puts "chomp" }
end
def emote
puts "[slience]"
end
end
class Duck < Animal
def emote
2.times { puts "quack" }
end
end
class Cat < Animal
def emote
if name == 'Grumpy'
puts "NO!"
else
puts "purrrr"
end
end
end
class Dog < Animal
def emote
10.times { puts "BARK!" }
end
end
quackers = Duck.new('Quackers')
quackers.eat
quackers.emote
grumpy_cat = Cat.new('Grumpy')
grumpy_cat.emote
annoying_dog = Dog.new('Yippy')
annoying_dog.emote
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment