Demonstrate how to dynamically add variables to an object (a class instance) at runtime.

This is useful when the methods/variables of an instance are based on a data file that isn't available until runtime. Hal Fulton gives an example of creating an OO CSV parser at An Exercise in Metaprogramming with Ruby. This is referred to as "monkeypatching" by Pythonistas and some others.

% package require TclOO
% oo::class create summation {
   constructor {} {
       variable v 0
   }
   method add x {
       variable v
       incr v $x
   }
   method value {{var v}} {
       variable $var
       return [set $var]
   }
   destructor {
       variable v
       puts "Ended with value $v"
   }
}
::summation
% set s [summation new]
% # Do the monkey patch!
% set [info object namespace $s]::time now
now
% # Prove it's really part of the object...
% $s value time
now
%