Class: Wref::Implementations::IdClassUnique
- Inherits:
-
Object
- Object
- Wref::Implementations::IdClassUnique
- Defined in:
- lib/wref/implementations/id_class_unique.rb
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #get ⇒ Object
- #get! ⇒ Object
-
#initialize(object) ⇒ IdClassUnique
constructor
A new instance of IdClassUnique.
Constructor Details
#initialize(object) ⇒ IdClassUnique
Returns a new instance of IdClassUnique.
2 3 4 5 6 7 |
# 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 |
Instance Method Details
#alive? ⇒ Boolean
41 42 43 44 45 46 47 |
# File 'lib/wref/implementations/id_class_unique.rb', line 41 def alive? if get return true else return false end end |
#get ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 |