From: Gary Wright Date: 2007-12-22T22:59:25+09:00 Subject: Re: Singleton Method On Dec 22, 2007, at 2:59 AM, Sebastian Hungerecker wrote: > Gary Wright wrote: >> 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. > > Yes, actually. > >> Your examples are different than mine. > > They are. They also don't make much sense. But they're still > equivalent > to each other. I was trying to point out that they didn't make sense relative to the previous examples in the thread, but Sebastian is correct to point out that they are equivalent to each other. It turns out that those definitions for Array.second end up returning arrays, in particular they return [1], since Array actually has a [] method, which construct and returns a new array. In Ryan's code, self[1], is actually a call to Array.[], which constructs the new array. Array.second returns [1] in those examples, something very different what I was showing in my examples. Gary.