"HarryO" <harryo / zipworld.com.au> writes:

> >      class File
> >        class <<self
> >          alias original open
> >        end

 
> If that's discussed in your book, can you give me a page or section
> reference?

'alias' works on instance methods. The class methods of class 'File'
are instance methods of File's metaclass, so we have to enter the
context of that metaclass to alias them.

To look at it a slightly different way:

   f = File.open(..)
   f.path

In the second line above, we're sending 'f' the message 'path'. The
'f' object handles this by looking in it's class for a method called
'path' and calling that method.

In the first line we're also sending a message, this time to the
object File. Where does _it_ look for methods? In _its_ class. This
class-of-a-class is File's metaclass, and it holds all of File's class
methods. We can get access to this class within File's class
definition using the class <<self notation, in the same way we can get
to any object's class using <<object.

There's a discussion of all this in chapter 19, which most folk
probably skip :)



Dave