In the Ruby Standard Library, we have a Singleton class:http://ruby-doc.org/stdlib/libdoc/singleton/rdoc/index.html
We can make any singleton class by including this class inside. I rarely see it being used. When would it be wise to use this Singleton class or just use the simple old class methods - also known as single-user mode methods?
It is said differently: which Singleton coding scheme is the best and why? Here are three ways I could think of:
require 'singleton' class Foo include Singleton # method definitions go here... end Foo.instance.do_something!
Against
class Foo class << self # method definitions go here... end end Foo.do_something!
module Foo class << self # method definitions go here... end end Foo.do_something!
WARNING : Opinions Ahead!
, :
class << (Foo = Object.new) # method definitions go here... end Foo.do_something!
. - . : , , factory .
, Ruby, , "Ruby": Ruby, Rails, Ruby, Smalltalk, Ruby, Java- Ruby Ruby? , .
, , , . , mixin extend . (, !)
extend
, , , , , .
, , - , . - .
Source: https://habr.com/ru/post/1785092/More articles:Google Analytics with Disabling MonoTouch on Device - iphonehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1785088/how-to-achieve-bottom-align-floated-div-that-sizes-to-its-container&usg=ALkJrhh5ae1GOtyN31PhhG10kBD1zjpu6Q.NET Start reading with DataReader before completing the query? - .netHow to insert a new node into xml_document using RapidXml for C ++ using strings? - c ++How to create nested groups in Django? - djangoJava and increasing the efficiency of genetic algorithms - javaSQL Split - insert into a hierarchical table structure - stringDatabase Design: Selecting and Restricting Favorites - databaseКак Android ActivityUnitTestCase включает целевое приложение AndroidManifest.xml? - androidGetting Maya Models on iPhone - iphoneAll Articles