From: "Mauricio Fernández" Date: 2002-12-02T05:12:06+09:00 Subject: Re: [FAQ] What do some of Ruby's symbols mean? On Mon, Dec 02, 2002 at 02:54:03AM +0900, Shannon Fang wrote: > Hi > > I appreciate the benefit. But some problem not clear: > > 1. what is the symbol %{ mean? I knew there are %w %Q %q etc, but %{ ?? > 2. My inital question about << is class << anObj. Don't know when it > became class << self?? Is << only used with self? > > After I understand why class << self, and re-read the pickaxe, I'll be > able to under stand your code better. > I assume you do already know singleton classes (and methods), so here's only the explanation of the class << self idiom. Inside a class definition, 'self' refers the the class object (that of class Class): irb(main):001:0> class A irb(main):002:1> puts self irb(main):003:1> end A nil irb(main):004:0> So when we do 'class << self' we're grabbing the current class object's singleton class to add to it a singleton method which will become a class method: So class A class << self def doit puts "BLA" end end end is mostly equivalent to class A def A.doit puts "BLA" end end See one of Guy's (ts) posts on this thread for more info. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com ...Deep Hack Mode -- that mysterious and frightening state of consciousness where Mortal Users fear to tread. -- Matt Welsh