Skip to content

Instantly share code, notes, and snippets.

@novill
novill / ruby-destructor-example.rb
Created April 3, 2019 09:33 — forked from iboard/ruby-destructor-example.rb
Ruby 'Destructor' example.
class Foo
attr_reader :bar
def initialize
@bar = 123
ObjectSpace.define_finalizer( self, self.class.finalize(bar) )
end
def self.finalize(bar)
proc { puts "DESTROY OBJECT #{bar}" }
end