From: Xavier Noria Date: 2007-01-05T05:23:32+09:00 Subject: Re: What does "extend self" do? On Jan 4, 2007, at 9:09 PM, Jeff wrote: > I happened to be reading dependencies.rb in the Rails source, and it > starts like this: > > require 'set' > require File.dirname(__FILE__) + '/core_ext/module/ > attribute_accessors' > require File.dirname(__FILE__) + '/core_ext/load_error' > require File.dirname(__FILE__) + '/core_ext/kernel' > > module Dependencies #:nodoc: > extend self > ... > > > What is the "extend self" doing? I thought at the top a module, > 'self' > was pretty much an empty context at that point... but I guess not, > since the writer obviously thinks self contains something worth > extending...? It extends the very module object. That's one-liner to add all the module instance methods as module functions. That is module Foo extend self def foo 'foo' end end allows the call Foo.foo. To do it by hand you'd add a module_function :method for each method. -- fxn