Last active
December 26, 2015 19:09
-
-
Save meaganewaller/7199459 to your computer and use it in GitHub Desktop.
OCP Principle Animal
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 Animal | |
def breathe(animal) | |
if animal == "cat" | |
puts "inhale and exhale" | |
elsif animal == "dog" | |
puts "inhale and exhale" | |
elsif animal == "cow" | |
puts "inhale and exhale" | |
end | |
end | |
def speak(animal) | |
if animal == "cat" | |
puts "meow" | |
elsif animal == "dog" | |
puts "bark" | |
elsif animal == "cow" | |
puts "moo" | |
end | |
end | |
end | |
cat = Animal.new | |
cat.breathe("cat") #=> "inhale and exhale" | |
cat.speak("cat") #=> "meow" | |
dog = Animal.new | |
dog.breathe("dog") #=> "inhale and exhale" | |
dog.speak("dog") #=> "bark" | |
cow = Animal.new | |
cow.breathe("cow") #=> "inhale and exhale" | |
cow.speak("cow") #=> "moo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment