Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/alt/ruby31/share/ruby
File: weakref.rb
# frozen_string_literal: true
[0] Fix | Delete
require "delegate"
[1] Fix | Delete
[2] Fix | Delete
# Weak Reference class that allows a referenced object to be
[3] Fix | Delete
# garbage-collected.
[4] Fix | Delete
#
[5] Fix | Delete
# A WeakRef may be used exactly like the object it references.
[6] Fix | Delete
#
[7] Fix | Delete
# Usage:
[8] Fix | Delete
#
[9] Fix | Delete
# foo = Object.new # create a new object instance
[10] Fix | Delete
# p foo.to_s # original's class
[11] Fix | Delete
# foo = WeakRef.new(foo) # reassign foo with WeakRef instance
[12] Fix | Delete
# p foo.to_s # should be same class
[13] Fix | Delete
# GC.start # start the garbage collector
[14] Fix | Delete
# p foo.to_s # should raise exception (recycled)
[15] Fix | Delete
#
[16] Fix | Delete
[17] Fix | Delete
class WeakRef < Delegator
[18] Fix | Delete
VERSION = "0.1.1"
[19] Fix | Delete
[20] Fix | Delete
##
[21] Fix | Delete
# RefError is raised when a referenced object has been recycled by the
[22] Fix | Delete
# garbage collector
[23] Fix | Delete
[24] Fix | Delete
class RefError < StandardError
[25] Fix | Delete
end
[26] Fix | Delete
[27] Fix | Delete
@@__map = ::ObjectSpace::WeakMap.new
[28] Fix | Delete
[29] Fix | Delete
##
[30] Fix | Delete
# Creates a weak reference to +orig+
[31] Fix | Delete
#
[32] Fix | Delete
# Raises an ArgumentError if the given +orig+ is immutable, such as Symbol,
[33] Fix | Delete
# Integer, or Float.
[34] Fix | Delete
[35] Fix | Delete
def initialize(orig)
[36] Fix | Delete
case orig
[37] Fix | Delete
when true, false, nil
[38] Fix | Delete
@delegate_sd_obj = orig
[39] Fix | Delete
else
[40] Fix | Delete
@@__map[self] = orig
[41] Fix | Delete
end
[42] Fix | Delete
super
[43] Fix | Delete
end
[44] Fix | Delete
[45] Fix | Delete
def __getobj__ # :nodoc:
[46] Fix | Delete
@@__map[self] or defined?(@delegate_sd_obj) ? @delegate_sd_obj :
[47] Fix | Delete
Kernel::raise(RefError, "Invalid Reference - probably recycled", Kernel::caller(2))
[48] Fix | Delete
end
[49] Fix | Delete
[50] Fix | Delete
def __setobj__(obj) # :nodoc:
[51] Fix | Delete
end
[52] Fix | Delete
[53] Fix | Delete
##
[54] Fix | Delete
# Returns true if the referenced object is still alive.
[55] Fix | Delete
[56] Fix | Delete
def weakref_alive?
[57] Fix | Delete
@@__map.key?(self) or defined?(@delegate_sd_obj)
[58] Fix | Delete
end
[59] Fix | Delete
end
[60] Fix | Delete
[61] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function