Skip to content

Instantly share code, notes, and snippets.

@ajmalafif
Created October 11, 2012 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajmalafif/3869895 to your computer and use it in GitHub Desktop.
Save ajmalafif/3869895 to your computer and use it in GitHub Desktop.
Bloc Shape Challenge
class Shape
attr_reader :color
def initialize(color)
@color = color
end
def can_fit?(shape)
self.area < shape.area ? true : false
end
def can_fit(shape)
self.area / shape.area
end
end
class Rectangle < Shape
def initialize(width, height, color = "Red")
super(color)
@width = width
@height = height
end
def area
@width * @height
end
end
class Square < Shape
def initialize(side, color = "Red")
super(color)
@side = side
end
def area
@side * @side
end
end
class Circle < Shape
def initialize(radius, color = "Red")
super(color)
@radius = radius
end
def area
@radius ** 2 * Math::PI
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment