On Behalf Of Paul S.:
is not clear
to me what triggers the execution of a statement such as "sayfoo
:rubyrocks" in your example.
When the class is loaded, when
yes, when class is first loaded or redefined.
an instance is created, ???
no, otherwise it gets executed many times per instance (assumming of
course you just want it to run once You can use initialize() if you
want something invoked per instance-iation.
btw, you can monitor behavior using irb and debug. but in case you doubt
if they do some magic, you can also do tracing. try putting the ff code
at the beginning of the program you want to observe,
set_trace_func proc do |event, file, line, id, binding, classname|
printf “%8s %s:%2d%10s %8s\n”, event, file, line, id, classname
ruby is really very open. have fun.
kind regards -botp