SapphireSteel Forum
Welcome, Guest. Please login or register.
June 19, 2013, 02:32:46 AM

Login with username, password and session length
Search:     Advanced search
Welcome to the SapphireSteel forum - for discussion of the Sapphire and Amethyst IDEs
3893 Posts in 803 Topics by 672 Members
Latest Member: davib
* Home Help Search Login Register
+  SapphireSteel Forum
|-+  General
| |-+  Ruby Programming
| | |-+  So, let's talk about Ruby...
« previous next »
Pages: [1] Print
Author Topic: So, let's talk about Ruby...  (Read 7391 times)
Huw Collingbourne
Administrator
Hero Member
*****
Posts: 937



« on: January 02, 2007, 04:09:43 PM »

...and maybe some Rails too.  Smiley

This is the place to ask questions and share ideas about Ruby programming in general. If you are a newcomer to Ruby, you might be interested in downloading our free eBook, The Little Book Of Ruby, to help to get you started. For a more in-depth guide, download The Book Of Ruby.

Please bear in mind that this forum is intended for users of SapphireSteel Software IDEs so please confine discussion to programming issues related to Ruby In Steel and/or the two SapphireSteel Software Ruby eBooks mentioned above.

best wishes
Huw
« Last Edit: June 25, 2010, 04:11:43 AM by Huw Collingbourne » Logged
papp.zoltan
Newbie
*
Posts: 6


« Reply #1 on: August 22, 2011, 08:54:01 AM »

I don't understand singleton methods. There is a same name but different meanings in Design Patterns.
Logged
Huw Collingbourne
Administrator
Hero Member
*****
Posts: 937



« Reply #2 on: August 22, 2011, 09:49:13 AM »

I've explained these in the Book. Can you tell me which elements you don't understand?

Best wishes

Huw
Logged
papp.zoltan
Newbie
*
Posts: 6


« Reply #3 on: August 23, 2011, 02:25:29 AM »

In Desing Patterns, singleton object mean there is only one and nothing more object created.
http://en.wikipedia.org/wiki/Singleton_pattern

If you understand Java here is the sample:

Quote
class Singleton
{
   private static Singleton instance;
   private Singleton()
   {
      ...
   }

   public static synchronized Singleton getInstance()
   {
      if (instance == null)
         instance = new Singleton();

      return instance;
   }
   ...
   public void doSomething()
   {
      ...   
   }
}

Singleton.getInstance().doSomething();
Logged
Huw Collingbourne
Administrator
Hero Member
*****
Posts: 937



« Reply #4 on: August 23, 2011, 02:41:05 AM »

I think that's similar to Ruby singletons. But in Ruby singleton is 'built in' to the language so you don't have to check if an instance exists before creating a singleton. The only confusing thing in Ruby is that there are several syntaxes for creating Singletons and singleton methods.

Singleton methods are methods that can be added to a specific object. So if you have class X and objects x1 and  2 you can add method y() to x2 but x1 won't have it.

A singleton class is a class which is used to create a single object. e.g.

Code:
ob = Object.new
  class << ob
    def blather( aStr )
      puts("blather, blather #{aStr}")
    end
  end

Here the unnamed class descends from object, defines methods etc in the usual way and adds them to the object called ob. Now ob is the only object with those methods. No other instance can be created from the class so it is a singleton. As I said there are other syntaxes too but fundamentally that's how singletons work in Ruby.

best wishes

Huw
Logged
ArunSakthivel
Newbie
*
Posts: 1


« Reply #5 on: February 06, 2012, 09:49:28 PM »

If you want to mare information about singleton check this link
http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again
Logged
petermmose
Newbie
*
Posts: 1



« Reply #6 on: March 19, 2012, 05:16:03 AM »

I have read your book, It was really very easy simple to understand and very informative also. It helped me a lot to understand the most powerful mix-in Functionality of ruby.
« Last Edit: March 19, 2012, 05:17:46 AM by petermmose » Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!