class Wref::Implementations::IdClassUnique
Public Class Methods
new(object)
click to toggle source
# File lib/wref/implementations/id_class_unique.rb, line 2 def initialize(object) @id = object.__id__ @class_name = object.class.name.to_sym ObjectSpace.define_finalizer(object, method(:destroy)) @unique_id = object.__wref_unique_id__ if object.respond_to?(:__wref_unique_id__) end
Public Instance Methods
alive?()
click to toggle source
# File lib/wref/implementations/id_class_unique.rb, line 41 def alive? if get return true else return false end end
get()
click to toggle source
# File lib/wref/implementations/id_class_unique.rb, line 15 def get return nil if !@class_name || !@id begin object = ObjectSpace._id2ref(@id) rescue RangeError destroy return nil end #Some times this class-name will be nil for some reason - knj object_class_name = object.class.name if !object_class_name || @class_name != object_class_name.to_sym || @id != object.__id__ destroy return nil end if @unique_id destroy return nil if !object.respond_to?(:__wref_unique_id__) || object.__wref_unique_id__ != @unique_id end return object end
get!()
click to toggle source
# File lib/wref/implementations/id_class_unique.rb, line 9 def get! object = get raise ::Wref::Recycled unless object return object end
Private Instance Methods
destroy(*args)
click to toggle source
# File lib/wref/implementations/id_class_unique.rb, line 51 def destroy(*args) @id = nil @class_name = nil @unique_id = nil end