Last active
August 29, 2015 14:15
-
-
Save LNA/79087e87143965dea875 to your computer and use it in GitHub Desktop.
Polymorphism
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
vogue_magazine = Magazine.new(vogue) | |
self_magazine = Magazine.new(self) | |
# How many pages are there in vogue magazine? | |
vogue_magazine.pages | |
# How many pages are there in self magazine? | |
self_magazine.pages | |
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 Magazine | |
def initialize(name) | |
@magazine = name | |
end | |
def pages | |
@magazine.pages | |
end | |
def cover_story | |
@magazine.cover_story | |
end | |
end |
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 SelfMagazine | |
def initialize(self) | |
@self = self | |
end | |
def pages | |
@self.pages | |
end | |
def cover_story | |
@self.cover_story | |
end | |
end |
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 VogueMagazine | |
def initialize(vouge) | |
@vogue = vogue | |
end | |
def pages | |
@vogue.pages | |
end | |
def cover_story | |
@vogue.cover_story | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment