-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsingleton-stdlib.rb
More file actions
29 lines (23 loc) · 834 Bytes
/
Copy pathsingleton-stdlib.rb
File metadata and controls
29 lines (23 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Design pattern Singleton en Ruby : avec la librairie standard de Ruby.
#---------------------------------------------------------------------
# Documentation sur la librairie : http://ruby-doc.org/stdlib-1.9.3/libdoc/singleton/rdoc/Singleton.html
# Code source (commenté) de la librairie : https://github.com/ruby/ruby/blob/trunk/lib/singleton.rb
# Spécifications du module Singleton : https://github.com/rubyspec/rubyspec/tree/master/library/singleton
# Import du module Singleton de la librairie standard.
require 'singleton'
# Création de la classe qui va être un singleton.
class Hermit
# mixin : On inclut le code du module Singleton dans la classe courante.
include Singleton
# C'est tout.
def talk
puts "I'm alone."
end
end
# Tests.
h = Hermit.instance
h.talk
puts h
i = Hermit.instance
i.talk
puts i