Forum: Ruby Singleton classes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8fa0f5c2bf8ad238baa4e20cb0360ebd?d=identicon&s=25 Matt Harrison (iwasinnamuknow)
on 2008-12-24 01:15
(Received via mailing list)
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
6e366eb5a71be2bad7f383d42aeb4788?d=identicon&s=25 Justin Collins (Guest)
on 2008-12-24 01:55
(Received via mailing list)
Matt Harrison wrote:
>   .....
> 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
8fa0f5c2bf8ad238baa4e20cb0360ebd?d=identicon&s=25 Matt Harrison (iwasinnamuknow)
on 2008-12-24 04:25
(Received via mailing list)
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
2a2d08e8e6f192991f0f93b56b79aab6?d=identicon&s=25 meng nan (Guest)
on 2009-01-07 05:09
(Received via mailing list)
# unsubscribe
This topic is locked and can not be replied to.