Created
August 26, 2015 04:01
-
-
Save modsognir/e1782a0519615d8f179e 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 Animal | |
def self.noise=(sound) | |
@noise = sound | |
end | |
def self.noise | |
@noise | |
end | |
def speak | |
self.class.noise | |
end | |
end | |
class Dog < Animal | |
self.noise = 'Woof' | |
end | |
class Cat < Animal | |
self.noise = 'Meeeeoowww' | |
end | |
> Cat.new.speak | |
=> "Meeeeoowww" | |
> Dog.new.speak | |
=> "Woof" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment