Last active
August 26, 2016 19:55
-
-
Save karloscodes/6bd7e03b99581b2b1525424dd5cbf1b0 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 Shape | |
def initialize(color) | |
@color = color | |
end | |
def repr | |
raise 'Abstract method, to be implemented on subclasses' | |
end | |
def draw | |
paint(repr) | |
end | |
private | |
def paint(repr) | |
puts @color, repr | |
end | |
end | |
class Triangle < Shape | |
def initialize(color, sides) | |
super(color) | |
@sides = sides | |
end | |
def repr | |
# It could be something more complex | |
@sides | |
end | |
end | |
class Square < Shape | |
def initialize(color, side) | |
super(color) | |
@side = side | |
end | |
def repr | |
# It could be something more complex | |
@side | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment