Skip to content

Instantly share code, notes, and snippets.

@raderj89
Last active December 27, 2015 04:09
Show Gist options
  • Save raderj89/7265196 to your computer and use it in GitHub Desktop.
Save raderj89/7265196 to your computer and use it in GitHub Desktop.
class Shape
attr_accessor :color
def can_fit?(shape)
area > shape.area
end
end
class Rectangle < Shape
attr_accessor :width, :height
def initialize(width, height, color="Red")
@width, @height, @color = width, height, color
end
def area
@width * @height
end
end
class Square < Rectangle
def initialize(width, color= "Red")
super(width, width, color)
end
end
class Circle < Shape
attr_accessor :radius
def initialize(radius, color= "Red")
@radius, @color = radius, color
end
def area
Math::PI * (radius ** 2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment