Skip to content

Instantly share code, notes, and snippets.

@colemanfoley
Created October 9, 2012 02:57
Show Gist options
  • Save colemanfoley/3856313 to your computer and use it in GitHub Desktop.
Save colemanfoley/3856313 to your computer and use it in GitHub Desktop.
Shape classes
class Shape
def get_color
return color
end
def set_color(color)
@color = color
end
def can_fit?(shape)
if self.get_area/shape.get_area >= 1
return true
end
else
return false
end
def can_fit(shape)
return self.get_area/shape.get_area
end
end
class Rectangle < Shape
attr_accessor :length
attr_accessor :width
attr_accessor :color
def initialize(width, height, color = "red")
@height = height
@width = width
@color = color
end
def get_area
return @height * @width
end
end
class Square < Shape
attr_accessor :side
attr_accessor :color
def initialize(side, color = "red")
@side = side
@color = color
end
def get_area
return side ** 2
end
end
class Circle < Shape
attr_accessor :radius
attr_accessor :color
def initialize(radius, color = "red")
@radius = radius
@color = color
end
def get_area
return 3.14159265358979 * (radius ** 2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment