dizballanze

My first singleton on Ruby

Jul 28th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.34 KB | None | 0 0
  1. class Single
  2.   private_class_method :new
  3.  
  4.   @@instance = nil
  5.  
  6.   def self.getInstance
  7.     @@instance = new if @@instance == nil
  8.     p "getInstance Call"
  9.   end
  10.  
  11.   def initialize
  12.     p "New instance!"
  13.   end
  14. end
  15.  
  16. obj1 = Single.getInstance
  17. obj2 = Single.getInstance
  18.  
  19. #"New instance!"
  20. #"getInstance Call"
  21. #"getInstance Call"
Advertisement
Add Comment
Please, Sign In to add comment