Posted to tcl by cchase at Fri May 27 17:14:36 GMT 2022view raw

  1. oo::class create Person {
  2. variable name
  3. variable age
  4.  
  5. method setName {args} {
  6. lassign $args name rest
  7. puts "Name set to $name"
  8. variable name $name
  9.  
  10. if {[llength $rest] > 0} {
  11. my {*}$rest
  12. }
  13.  
  14. }
  15.  
  16. method setAge {args} {
  17. lassign $args age rest
  18. puts "Age set to $age"
  19. variable age $age
  20.  
  21. if {[llength $rest] > 0} {
  22. my {*}$rest
  23. }
  24. }
  25.  
  26. method details {} {
  27. variable name
  28. variable age
  29.  
  30. puts "$name is $age years old"
  31. }
  32. }
  33.  
  34. Person create guy
  35.  
  36. guy setName Bob {setAge 33}