fork download
  1. Object subclass: #Square.
  2. Square instanceVariableNames: 'side'.
  3. Square class extend [
  4. new: square [
  5. | r |
  6. <category: 'instance creation'>
  7. r := super new.
  8. r init: square.
  9. ^r
  10. ]
  11. ]
  12. Square extend [
  13. init: square [
  14. <category: 'initialization'>
  15. side := square sqrt.
  16. ]
  17. perimeter [
  18. | p |
  19. <category: 'perimeter calculation'>
  20. p := 4 * side.
  21. ^p
  22. ]
  23. ]
  24.  
  25. | s |
  26. s := Square new: 4.
  27. (s perimeter) printNl
Success #stdin #stdout 0s 335360KB
stdin
Standard input is empty
stdout
8.0