On 11 Jan 2007, at 13:36, Paul Smith wrote: > Thanks for the explanation David. > > However, it is still not clear to me when these statements are > invoked. > > In your example, what triggers the execution of the 2 statements? > >> class C < SomeClass >> puts "self right now is #{self}." # self right now is C. >> do_something # Hi! >> end > > When the class is loaded, when an instance of that class is created? > Is this similar to a static initialization block in Java? > > P. Hemant may have already answered your question, but as an aside the easiest way to check these things in Ruby is to use irb to test: irb(main):001:0> class A irb(main):002:1> def self.doit irb(main):003:2> puts "hi" irb(main):004:2> end irb(main):005:1> end => nil irb(main):006:0> class B < A irb(main):007:1> puts "self: #{self}" irb(main):008:1> doit irb(main):009:1> end self: B hi => nil irb(main):010:0> A.new => #<A:0x340fe4> irb(main):011:0> B.new => #<B:0x33aab8> Does that make it clearer? doit only gets run when the B class is defined, not when an instance is created. Alex Gutteridge Bioinformatics Center Kyoto University