From: dblack@... Date: 2006-10-10T17:46:50+09:00 Subject: Re: "def self.method" vs "class << self; def method" Hi -- On Tue, 10 Oct 2006, Ken Bloom wrote: > joevandyk@gmail.com wrote: >> What's the difference between >> >> class Foo >> class << self >> def foo; end >> end >> end >> >> and >> >> class Foo >> def self.foo; end >> end > > AFAIK nothing. But you can't do the second one with most > metaprogrammed methods, for example attr_accessor. That's a different matter, though (if I'm understanding your point correctly); the difference between: class C attr_accessor :x # and class << self attr_accessor :x is not a limitation or exception -- it's just that you're calling attr_accessor on two different objects (C and C's singleton class). The first attr_accessor doesn't write methods in the singleton class, so it's not analogous to def self.x. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org