Created
August 27, 2013 20:21
-
-
Save radavis/6358648 to your computer and use it in GitHub Desktop.
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 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