Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../proc/self/root/usr/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
[19] Fix | Delete
##
[20] Fix | Delete
# RefError is raised when a referenced object has been recycled by the
[21] Fix | Delete
# garbage collector
[22] Fix | Delete
[23] Fix | Delete
class RefError < StandardError
[24] Fix | Delete
end
[25] Fix | Delete
[26] Fix | Delete
@@__map = ::ObjectSpace::WeakMap.new
[27] Fix | Delete
[28] Fix | Delete
##
[29] Fix | Delete
# Creates a weak reference to +orig+
[30] Fix | Delete
#
[31] Fix | Delete
# Raises an ArgumentError if the given +orig+ is immutable, such as Symbol,
[32] Fix | Delete
# Integer, or Float.
[33] Fix | Delete
[34] Fix | Delete
def initialize(orig)
[35] Fix | Delete
case orig
[36] Fix | Delete
when true, false, nil
[37] Fix | Delete
@delegate_sd_obj = orig
[38] Fix | Delete
else
[39] Fix | Delete
@@__map[self] = orig
[40] Fix | Delete
end
[41] Fix | Delete
super
[42] Fix | Delete
end
[43] Fix | Delete
[44] Fix | Delete
def __getobj__ # :nodoc:
[45] Fix | Delete
@@__map[self] or defined?(@delegate_sd_obj) ? @delegate_sd_obj :
[46] Fix | Delete
Kernel::raise(RefError, "Invalid Reference - probably recycled", Kernel::caller(2))
[47] Fix | Delete
end
[48] Fix | Delete
[49] Fix | Delete
def __setobj__(obj) # :nodoc:
[50] Fix | Delete
end
[51] Fix | Delete
[52] Fix | Delete
##
[53] Fix | Delete
# Returns true if the referenced object is still alive.
[54] Fix | Delete
[55] Fix | Delete
def weakref_alive?
[56] Fix | Delete
@@__map.key?(self) or defined?(@delegate_sd_obj)
[57] Fix | Delete
end
[58] Fix | Delete
end
[59] Fix | Delete
[60] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function