Skip to content

Instantly share code, notes, and snippets.

@rlb3
Created July 2, 2013 14:45
Show Gist options
  • Select an option

  • Save rlb3/5909896 to your computer and use it in GitHub Desktop.

Select an option

Save rlb3/5909896 to your computer and use it in GitHub Desktop.
Destructor in ruby?
#!/usr/bin/env ruby
class MyObject
def initialize
ObjectSpace.define_finalizer(self, proc { destroy })
end
def start
puts 'start'
end
def destroy
puts 'DESTROY'
end
end
m = MyObject.new
m.start
# Ξ ~ → ruby test2.rb
# start
# DESTROY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment