Last active
December 27, 2015 04:09
-
-
Save raderj89/7265196 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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