RubyFlow The Ruby and Rails community linklog

Ruby Singleton Pattern

Ruby Singleton Pattern and usage example with Twitter gem to collect your friends timeline.

Comments

Another newbie poorly learns the singleton and wants to share the knowledge so other newbies can write code I am going to have to fix before it goes to production.

Why is the singleton to be used? What is it good for? Why translate your Java code to ruby and think that is the way to do it? Ever thought about using Module to implement a singleton?

Ever thought about using google to see the bajillion other blogs on this same subject that are better before you post?

Ever thought about writing the comment without judging or insulting people you don’t know?

@CriticOfAnonymousCritic: You might not like my tone but I am encouraging the poster to think before posting. Is that such a crime? If you are putting yourself out there then you have to be able to handle criticism. This is the real world after all.

@AnonymousCritic: If there is no real usage for Singleton pattern, why should Ruby Standard Library implement the Singleton module?

@dalibor: I didn’t say there wasn’t a use case for the Singleton at all. Instead I wanted the poster to answer my questions and avoid the java2ruby direct translation.

Just a quick note that I removed the blog post after receiving too much negative critic. :) Thanks for those that commented here and on the blog post.

Fuck AnonymousCritic. Don’t give up and don’t remove your post. If you want to blog why not treat feedback as fodder for an update or follow up post?

How about a post on the different ways a singleton can be implemented in Ruby and the (dis)advantages of each? I’d be interested to know why the Singleton module exists given a class is already a singleton object? If I make the constructor private don’t I now have a singleton without the need to call MySingleton#instance ?

@AnonymousWoodDuck: You may want the check the new post Ruby Singleton Pattern Again.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in