[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 17:47:28
Message-ID: 200410211344.52319.transami () runbox ! com
[Download RAW message or body]
On Thursday 21 October 2004 10:04 am, Gavin Kistner wrote:
| On Oct 20, 2004, at 4:16 PM, trans. (T. Onoma) wrote:
| > module ThisInstance
| > class << self
| > def hello
| > puts "Hello World!"
| > end
| > end
| > end
|
| Thank you for this; I'm just starting my project, and I have 6
| 'major-feature' handlers which are all Singleton classes -- namespace
| and functional-separation wrappers for a bunch of methods. The above
| smells cleaner to me.
From the responses (thanks for those BTW!) I gather that using modules in this
way is only good if there is no _state_ involved. As Brian points out there
are thread safety issues otherwise. In other words this is good if it's just
a bag of functions --a `toolbox` if you will.
But David has also pointed out that rather then use the a heavy Singleton
class, the virtual class (also called singleton) is probably better.
a = Object.new
class << a
def hello
puts "Hellow World!
end
end
As long as you don't need to ask a.is_a?(SpecialThing) this is lighter weight
solution. But I'm not sure right off how that plays into the initialization
difference you raise. Have any notions on that?
Likewise Thanks,
T.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic