Guest User

Untitled

a guest
Mar 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. class Rectangle
  2. attr_accessor :height, :width
  3.  
  4. def calculate_area
  5. width * height
  6. end
  7. end
  8.  
  9. class Square < Rectangle
  10. def width=(width)
  11. super(width)
  12. @height = width
  13. end
  14.  
  15. def height=(height)
  16. super(height)
  17. @width = height
  18. end
  19. end
  20.  
  21. rectangle = Rectangle.new
  22. rectangle.height = 10
  23. rectangle.width = 5
  24. rectangle.calculate_area # => 50
  25.  
  26. square = Square.new
  27. square.height = 10
  28. square.width = 5
  29. square.calculate_area # => 25
Add Comment
Please, Sign In to add comment