From: dblack@... Date: 2006-10-10T10:25:17+09:00 Subject: Re: "def self.method" vs "class << self; def method" Hi -- On Tue, 10 Oct 2006, 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 In the general case of class << obj; def x, vs. def obj.x, there's a difference in the scoping of constants: A = 1 class C A = 2 end c = C.new class << c def x puts A # this is C's A end end def c.y puts A # this is top-level A end c.x c.y But I don't think this will loom very large in the class-method case. Any constants you define in the class scope will be visible in both the methods. There may be some way to squeeze a difference out of them by defining methods in Class or something... but they're basically interchangeable. 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