Linux server1.dn-server.com 4.18.0-553.89.1.lve.el8.x86_64 #1 SMP Wed Dec 10 13:58:50 UTC 2025 x86_64
LiteSpeed
Server IP : 195.201.204.189 & Your IP : 216.73.216.37
Domains :
Cant Read [ /etc/named.conf ]
User : beriska1
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
opt /
alt /
ruby19 /
share /
ri /
1.9.1 /
system /
Singleton /
Delete
Unzip
Name
Size
Permission
Date
Action
_dump-i.ri
249
B
-rw-r--r--
2023-07-26 17:26
_load-c.ri
251
B
-rw-r--r--
2023-07-26 17:26
append_features-c.ri
173
B
-rw-r--r--
2023-07-26 17:26
cdesc-Singleton.ri
3.09
KB
-rw-r--r--
2023-07-26 17:26
clone-i.ri
224
B
-rw-r--r--
2023-07-26 17:26
dup-i.ri
219
B
-rw-r--r--
2023-07-26 17:26
included-c.ri
161
B
-rw-r--r--
2023-07-26 17:26
Save
Rename
U:RDoc::NormalModule[iI"Singleton:EF@0o:RDoc::Markup::Document:@parts[o;;[o:RDoc::Markup::Paragraph;[I";The Singleton module implements the Singleton pattern.;To:RDoc::Markup::BlankLine S:RDoc::Markup::Heading: leveli: textI" Usage;T@o; ;[I"8To use Singleton, include the module in your class.;T@o:RDoc::Markup::Verbatim;[ I"class Klass ;FI" include Singleton ;FI" # ... ;FI" end ;Fo; ;[I"AThis ensures that only one instance of Klass can be created.;T@o;;[I"+a,b = Klass.instance, Klass.instance ;FI" ;FI"a == b ;FI"# => true ;FI" ;FI"Klass.new ;FI"-# => NoMethodError - new is private ... ;Fo; ;[I"HThe instance is created at upon the first call of Klass.instance().;T@o;;[I"class OtherKlass ;FI" include Singleton ;FI" # ... ;FI" end ;FI" ;FI"+ObjectSpace.each_object(OtherKlass){} ;FI"# => 0 ;FI" ;FI"OtherKlass.instance ;FI"+ObjectSpace.each_object(OtherKlass){} ;FI"# => 1 ;Fo; ;[I">This behavior is preserved under inheritance and cloning.;T@S;;i; I"Implementation;T@o; ;[I"This above is achieved by:;T@o:RDoc::Markup::List: @type:BULLET:@items[ o:RDoc::Markup::ListItem:@label0;[o; ;[I"1Making Klass.new and Klass.allocate private.;T@o;;0;[o; ;[I"OOverriding Klass.inherited(sub_klass) and Klass.clone() to ensure that the;TI"=Singleton properties are kept when inherited and cloned.;T@o;;0;[o; ;[I"LProviding the Klass.instance() method that returns the same object each;TI"time it is called.;T@o;;0;[o; ;[I":Overriding Klass._load(str) to call Klass.instance().;T@o;;0;[o; ;[I"HOverriding Klass#clone and Klass#dup to raise TypeErrors to prevent;TI"cloning or duping.;T@S;;i; I"Singleton and Marshal;T@o; ;[ I"RBy default Singleton's #_dump(depth) returns the empty string. Marshalling by;TI"Ldefault will strip state information, e.g. instance variables and taint;TI"Istate, from the instance. Classes using Singleton can provide custom;TI"P_load(str) and _dump(depth) methods to retain some of the previous state of;TI"the instance.;T@o;;["I"require 'singleton' ;FI" ;FI"class Example ;FI" include Singleton ;FI"# attr_accessor :keep, :strip ;FI" def _dump(depth) ;FI"@ # this strips the @strip information from the instance ;FI"$ Marshal.dump(@keep, depth) ;FI" end ;FI" ;FI" def self._load(str) ;FI"+ instance.keep = Marshal.load(str) ;FI" instance ;FI" end ;FI" end ;FI" ;FI"a = Example.instance ;FI"a.keep = "keep this" ;FI"!a.strip = "get rid of this" ;FI" a.taint ;FI" ;FI"$stored_state = Marshal.dump(a) ;FI" ;FI"a.keep = nil ;FI"a.strip = nil ;FI"$b = Marshal.load(stored_state) ;FI"p a == b # => true ;FI"!p a.keep # => "keep this" ;FI"p a.strip # => nil;F: @fileI"lib/singleton.rb;T;0[ [ [ [[I" class;F[[:public[[I" _load;T@�[:protected[ [:private[[I"append_features;F@�[I" included;F@�[I" instance;F[[;[[I" _dump;F@�[I" clone;F@�[I"dup;F@�[;[ [;[