Class: Farce::WeakRef

Inherits:
Delegator
  • Object
show all
Includes:
Internal::MarshalSupport::WeakRef
Defined in:
lib/farce/weak_ref.rb,
lib/farce/integrations/active_support/duplicable.rb

Overview

Drop-in replacement for Ruby's WeakRef class that is Ractor-friendly.

Examples:

foo = Object.new               # create a new object instance
p foo.to_s                     # original's class
foo = Farce::WeakRef.new(foo)  # reassign foo with WeakRef instance
p foo.to_s                     # should be same class
GC.start                       # start the garbage collector
p foo.to_s                     # should raise exception (recycled)

Constant Summary collapse

RefError =

Alias for Farce::WeakRefError to mimic ::WeakRef::RefError

WeakRefError

ActiveSupport Integration collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ WeakRef

Returns a new instance of WeakRef.



42
43
44
45
46
# File 'lib/farce/weak_ref.rb', line 42

def initialize(value)
  @value = WeakValue.new(value)
  super
  Kernel.instance_method(:freeze).bind_call(self)
end

Instance Method Details

#duplicable? ⇒ Boolean

Note:

This methods is only available if ActiveSupport has been loaded.

Returns true.

Returns:

  • (Boolean) —

    true



24
# File 'lib/farce/integrations/active_support/duplicable.rb', line 24

def duplicable? = true

#weakref_alive? ⇒ Boolean

Returns true if the referenced object is still alive and reachable.

Returns:

  • (Boolean) —

    true if the referenced object is still alive and reachable



55
# File 'lib/farce/weak_ref.rb', line 55

def weakref_alive? = @value.alive?