[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Singleton Class or Module Functions?
From:       "trans.  (T. Onoma)" <transami () runbox ! com>
Date:       2004-10-21 1:36:50
Message-ID: 200410202136.43499.transami () runbox ! com
[Download RAW message or body]

On Wednesday 20 October 2004 08:44 pm, David A. Black wrote:
| Hi --
|
| On Thu, 21 Oct 2004, trans.  (T. Onoma) wrote:
| > I've come across this seemingly indistinct option too many times now.
| > Which is better? Why choose one over the other?
| >
| >   module ThisInstance
| >     class << self
| >       def hello
| >         puts "Hello World!"
| >       end
| >     end
| >   end
| >
| >   ThisInstance.ameth
| >
| > or
| >
| >   class This
| >     include Singleton
| >     def hello
| >       puts "Hello World!"
| >     end
| >   end
| >
| >   This.instance.ameth
|
| (Do you mean 'hello' rather than 'ameth'?)

Yes.

| I'm not sure what you mean.  What's the connection between them?

It seems the above two types of constructs can be used interchangeably. They 
both have but one "instance". The both have the same access to methods. The 
singleton has to be instantiated the first go around, but since that's behind 
the scenes, that doesn't really make any difference (or does it?).

T.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic