Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment