/opt/cpanel/ea-ruby27/root/usr/share/ruby/ruby-2.7.8
NameSizeModeActions
benchmark/-0755rm
bigdecimal/-0755rm
bundler/-0755rm
cgi/-0755rm
csv/-0755rm
delegate/-0755rm
did_you_mean/-0755rm
digest/-0755rm
drb/-0755rm
fiddle/-0755rm
forwardable/-0755rm
getoptlong/-0755rm
io/-0755rm
irb/-0755rm
json/-0755rm
logger/-0755rm
matrix/-0755rm
net/-0755rm
observer/-0755rm
open3/-0755rm
openssl/-0755rm
optparse/-0755rm
ostruct/-0755rm
pstore/-0755rm
psych/-0755rm
racc/-0755rm
rdoc/-0755rm
reline/-0755rm
rexml/-0755rm
rinda/-0755rm
ripper/-0755rm
rss/-0755rm
rubygems/-0755rm
singleton/-0755rm
syslog/-0755rm
timeout/-0755rm
tracer/-0755rm
unicode_normalize/-0755rm
uri/-0755rm
webrick/-0755rm
yaml/-0755rm
abbrev.rb35290644editdlrm
base64.rb33790644editdlrm
benchmark.rb184530644editdlrm
bigdecimal.rb240644editdlrm
bundler.rb237180644editdlrm
cgi.rb100370644editdlrm
coverage.rb3680644editdlrm
csv.rb556430644editdlrm
date.rb10660644editdlrm
debug.rb306240644editdlrm
delegate.rb113430644editdlrm
did_you_mean.rb38060644editdlrm
digest.rb28940644editdlrm
drb.rb500644editdlrm
English.rb62580644editdlrm
erb.rb295040644editdlrm
expect.rb22170644editdlrm
fiddle.rb17220644editdlrm
fileutils.rb492710644editdlrm
find.rb25260644editdlrm
forwardable.rb91300644editdlrm
getoptlong.rb157870644editdlrm
ipaddr.rb199890644editdlrm
irb.rb276030644editdlrm
json.rb18090644editdlrm
kconv.rb58610644editdlrm
logger.rb167920644editdlrm
matrix.rb617030644editdlrm
mkmf.rb885390644editdlrm
monitor.rb69200644editdlrm
mutex_m.rb22140644editdlrm
observer.rb59710644editdlrm
open-uri.rb260880644editdlrm
open3.rb223360644editdlrm
openssl.rb4690644editdlrm
optionparser.rb590644editdlrm
optparse.rb609190644editdlrm
ostruct.rb107850644editdlrm
pathname.rb165580644editdlrm
pp.rb159780644editdlrm
prettyprint.rb162760644editdlrm
prime.rb126700644editdlrm
pstore.rb150630644editdlrm
psych.rb217180644editdlrm
racc.rb1370644editdlrm
rdoc.rb50000644editdlrm
readline.rb1130644editdlrm
reline.rb132530644editdlrm
resolv-replace.rb18050644editdlrm
resolv.rb752800644editdlrm
ripper.rb24940644editdlrm
rss.rb29630644editdlrm
rubygems.rb391080644editdlrm
securerandom.rb95280644editdlrm
set.rb246220644editdlrm
shellwords.rb68160644editdlrm
singleton.rb41580644editdlrm
socket.rb447020644editdlrm
tempfile.rb112130644editdlrm
time.rb245900644editdlrm
timeout.rb40750644editdlrm
tmpdir.rb41420644editdlrm
tracer.rb66400644editdlrm
tsort.rb146420644editdlrm
un.rb102020644editdlrm
uri.rb30390644editdlrm
weakref.rb14730644editdlrm
webrick.rb68900644editdlrm
yaml.rb18450644editdlrm
Edit: /opt/cpanel/ea-ruby27/root/usr/share/ruby/ruby-2.7.8/singleton.rb (4158B)
# frozen_string_literal: false # The Singleton module implements the Singleton pattern. # # == Usage # # To use Singleton, include the module in your class. # # class Klass # include Singleton # # ... # end # # This ensures that only one instance of Klass can be created. # # a,b = Klass.instance, Klass.instance # # a == b # # => true # # Klass.new # # => NoMethodError - new is private ... # # The instance is created at upon the first call of Klass.instance(). # # class OtherKlass # include Singleton # # ... # end # # ObjectSpace.each_object(OtherKlass){} # # => 0 # # OtherKlass.instance # ObjectSpace.each_object(OtherKlass){} # # => 1 # # # This behavior is preserved under inheritance and cloning. # # == Implementation # # This above is achieved by: # # * Making Klass.new and Klass.allocate private. # # * Overriding Klass.inherited(sub_klass) and Klass.clone() to ensure that the # Singleton properties are kept when inherited and cloned. # # * Providing the Klass.instance() method that returns the same object each # time it is called. # # * Overriding Klass._load(str) to call Klass.instance(). # # * Overriding Klass#clone and Klass#dup to raise TypeErrors to prevent # cloning or duping. # # == Singleton and Marshal # # By default Singleton's #_dump(depth) returns the empty string. Marshalling by # default will strip state information, e.g. instance variables from the instance. # Classes using Singleton can provide custom _load(str) and _dump(depth) methods # to retain some of the previous state of the instance. # # require 'singleton' # # class Example # include Singleton # attr_accessor :keep, :strip # def _dump(depth) # # this strips the @strip information from the instance # Marshal.dump(@keep, depth) # end # # def self._load(str) # instance.keep = Marshal.load(str) # instance # end # end # # a = Example.instance # a.keep = "keep this" # a.strip = "get rid of this" # # stored_state = Marshal.dump(a) # # a.keep = nil # a.strip = nil # b = Marshal.load(stored_state) # p a == b # => true # p a.keep # => "keep this" # p a.strip # => nil # module Singleton # Raises a TypeError to prevent cloning. def clone raise TypeError, "can't clone instance of singleton #{self.class}" end # Raises a TypeError to prevent duping. def dup raise TypeError, "can't dup instance of singleton #{self.class}" end # By default, do not retain any state when marshalling. def _dump(depth = -1) '' end module SingletonClassMethods # :nodoc: def clone # :nodoc: Singleton.__init__(super) end # By default calls instance(). Override to retain singleton state. def _load(str) instance end def instance # :nodoc: return @singleton__instance__ if @singleton__instance__ @singleton__mutex__.synchronize { return @singleton__instance__ if @singleton__instance__ @singleton__instance__ = new() } @singleton__instance__ end private def inherited(sub_klass) super Singleton.__init__(sub_klass) end end class << Singleton # :nodoc: def __init__(klass) # :nodoc: klass.instance_eval { @singleton__instance__ = nil @singleton__mutex__ = Thread::Mutex.new } klass end private # extending an object with Singleton is a bad idea undef_method :extend_object def append_features(mod) # help out people counting on transitive mixins unless mod.instance_of?(Class) raise TypeError, "Inclusion of the OO-Singleton module in module #{mod}" end super end def included(klass) super klass.private_class_method :new, :allocate klass.extend SingletonClassMethods Singleton.__init__(klass) end end ## # :singleton-method: _load # By default calls instance(). Override to retain singleton state. ## # :singleton-method: instance # Returns the singleton instance. end