[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Singleton classes

Matt Harrison

12/24/2008 12:06:00 AM

I'm trying to implement the singleton design in some classes. According
to ruby-doc.org[1] page on singletons, it should be fairly straightforward.

Unfortunately, I'm running into problems. Take the following declaration:

class Config
require 'yaml'
include Singleton

.....
end

When trying to use the class I get:

uninitialized constant Config::Singleton (NameError)

Also, I am not sure how to change from using the initialize method.
Normally, the Config class is initialized with a username, and then
provides methods to load/save, add/delete config directives.

Any tips on converting this class much apprecited.

Thanks

Matt

3 Answers

Justin Collins

12/24/2008 12:45:00 AM

0

Matt Harrison wrote:
> I'm trying to implement the singleton design in some classes.
> According to ruby-doc.org[1] page on singletons, it should be fairly
> straightforward.
>
> Unfortunately, I'm running into problems. Take the following declaration:
>
> class Config
> require 'yaml'
> include Singleton
>
> .....
> end
>
> When trying to use the class I get:
>
> uninitialized constant Config::Singleton (NameError)
>
> Also, I am not sure how to change from using the initialize method.
> Normally, the Config class is initialized with a username, and then
> provides methods to load/save, add/delete config directives.
>
> Any tips on converting this class much apprecited.
>
> Thanks
>
> Matt
>

require 'singleton'

will take care of the first issue. As far as how to pass in arguments to
initialize the instance, I played around with it a little but didn't see
an obvious way of doing it.

-Justin

Matt Harrison

12/24/2008 3:16:00 AM

0

Justin Collins wrote:
> require 'singleton'
>
> will take care of the first issue. As far as how to pass in arguments to
> initialize the instance, I played around with it a little but didn't see
> an obvious way of doing it.
>
> -Justin
>

Excellent, thanks. I think the docs for that class could be a little
clearer.

As for the initialize problem, I just moved the code from that method
into a normal method. So where in initialize it took a filename and
opened the file, I just moved that into a "load" method.

Thanks for the help.

Matt

meng nan

1/7/2009 2:48:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

# unsubscribe