Morton Goldberg
11/12/2007 6:37:00 PM
On Nov 12, 2007, at 8:54 AM, Gamont Gamont wrote:
> Im see this example and i didnt understand how it works.
> I dont find doc abou this construct.
>
> I find about object-specific class (class <<a), but here
> its a class.
>
> class <<Time
> alias old_now now
> def now
> old_now.to_f * FACTOR
> end
> end
>
> and when this statement executes
>
> Time.now, it calls the method in anonymous class and
> no more in Time class.
No, this code doesn't change where the 'now' method resides. Time.now
always calls the 'now' method in its singleton class.
> How this works ?
It works because Time is an object as well as a class. So Time can
(and does) have a singleton class (what you call an object-specific
class) just as any other object can. The singleton class of a class
is where class methods are defined, so the code you show simply
overrides the Time class method 'now'.
Regards, Morton