Skip to content

Instantly share code, notes, and snippets.

@karloscodes
Last active August 26, 2016 19:55
Show Gist options
  • Save karloscodes/6bd7e03b99581b2b1525424dd5cbf1b0 to your computer and use it in GitHub Desktop.
Save karloscodes/6bd7e03b99581b2b1525424dd5cbf1b0 to your computer and use it in GitHub Desktop.
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