Skip to content

Instantly share code, notes, and snippets.

@oneawayman
Created February 6, 2014 13:19
Show Gist options
  • Save oneawayman/8843951 to your computer and use it in GitHub Desktop.
Save oneawayman/8843951 to your computer and use it in GitHub Desktop.
Bloc Web Development Advanced Classes Checkpoint
## Inheritance ##
class Shape
attr_accessor :color
def initialize(color = nil)
@color = color || 'Red'
end
def larger_than?(shape)
if self.area >= shape.area
true
else
false
end
end
end
class Rectangle < Shape
attr_accessor :width, :height
def initialize(width, height, color = nil)
@width, @height = width, height
super(color)
end
def area
@width * @height
end
end
class Square < Rectangle
def initialize(side, color = nil)
@width, @height = width, height
super(side, side, color)
end
end
class Circle < Shape
attr_accessor :radius
def initialize(radius, color =nil)
@radius = radius
super(color)
end
def area
p Math::PI * (radius*radius)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment