[colug-432] ruby class variable behavior?

Jeff Frontz jeff.frontz at gmail.com
Tue Jan 12 15:20:17 EST 2016


On Tue, Jan 12, 2016 at 2:17 PM, Rick Hornsby <richardjhornsby at gmail.com>
wrote:

> Is the exceptions.yml file loaded each time a new instance of the class is
> created, and it just overwrites the @@audit_exceptions class variable?  Or
> is it loaded just once the first time myClass.new is invoked?


>From this SO posting (http://stackoverflow.com/a/2416407/318902 ) it sounds
like ruby "class" variables are like C++ static member variables -- i.e.,
only one execution of the initialization (and one actual instance) for all
instances of the class.  The second question is when does this happen --
with C++, it's via the static initialization routine, before main() is
called. This posting ( https://www.ruby-forum.com/topic/809975 ) says that
class variables are initialized at "class definition time", which I would
take to be when the second "end" is encountered above.

Can you use strace() to verify?

Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.colug.net/pipermail/colug-432/attachments/20160112/8545626b/attachment.html 


More information about the colug-432 mailing list