Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Rectangle
attr_accessor :height, :width
def calculate_area
width * height
end
end
class Square < Rectangle
def width=(width)
super(width)
@height = width
end
def height=(height)
super(height)
@width = height
end
end
rectangle = Rectangle.new
rectangle.height = 10
rectangle.width = 5
rectangle.calculate_area # => 50
square = Square.new
square.height = 10
square.width = 5
square.calculate_area # => 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment