From: Gary Wright Date: 2007-12-22T16:51:14+09:00 Subject: Re: Singleton Method On Dec 22, 2007, at 1:35 AM, Ryan Lewis wrote: > So defining the 'second' method like so: > def Array.second > self[1] > end > > is the same is making the singleton class like below. > Class << Array > def second > self[1] > end > end No. Your examples are different than mine. In your examples you are defining a singleton method for 'Array', which is an object that just happens to be a class. In my examples I defined a singleton method for one particular array, not all arrays, and not the object known as Array. Let's see if I can summarize things a bit: All method definitions wind up being stored in a module of one sort or another (which includes classes since Class is a subclass of Module, i.e. every class is also a module). 1) standard modules (instances of Module) -- the methods are called instance methods 2) standard classes (instances of Class) -- the methods are called instance methods 3) singleton classes of non-class/non-module objects -- the methods are called singleton methods 4) singleton classes of instances of Module -- the methods are called module methods or singleton methods of a (particular) module 5) singleton classes of instances of Class -- the methods are called class methods or singleton methods of a (particular) class. Since singleton classes are also classes, you can get an infinite regress of singleton methods of a singleton class of a singleton class of a... But just set that aside for the moment. Here is what the code looks like for the cases I listed: # case 1 module Enumerable def foo; end end # case 2 class Array def foo; end end # case 3 a = Object.new def a.foo; end # also case 3 class <