[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: statement outside of any method in a class

Peña, Botp

1/11/2007 9:35:00 AM

On Behalf Of Paul Smith:
# 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
end
#----

ruby is really very open. have fun.

kind regards -botp