From: daz Date: 2003-06-20T12:31:42+09:00 Subject: Re: class X; class << X : what is this idiom ? "you CAN teach an old dog ..." wrote in message news:a6e48b6b.0306181426.62e8d934@posting.google.com... > I have seen this idiom quite a few times, and have not figured out > what it does (looking at the pickaxe book). Could someone help > enlighten me? > > [My guess is that it creates a customized meta-class that X is an > instance of; am I guessing right?] That sounds a bit comp.sci :-) It's usually a prelude to one or more class method definitions. http://www.rubygarden.org/ruby?ClassMethods class Roo class << Roo # or class << self def class_meth1 end def class_meth2 p 'class_meth2' end end def Roo.class_meth3 # The usual(?) way p 'class_meth3' end def inst_meth1 p 'inst_meth1' end end Roo.class_meth2 Roo.class_meth3 r1 = Roo.new r1.inst_meth1 r2 = Roo.new r2.inst_meth1 #-> "class_meth2" #-> "class_meth3" #-> "inst_meth1" #-> "inst_meth1" daz