Skip to content

Instantly share code, notes, and snippets.

@ka8725
Last active January 3, 2016 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ka8725/983d497767d25dc3fd66 to your computer and use it in GitHub Desktop.
Save ka8725/983d497767d25dc3fd66 to your computer and use it in GitHub Desktop.
1 module HasFinalize
2 def self.included(base)
3 base.class_eval do
4 private
5
6 def finalize(&block)
7 ObjectSpace.define_finalizer(self, &block)
8 end
9 end
10 end
11 end
12
13 class T
14 include HasFinalize
15
16 def initialize
17 x = 100
18 finalize { puts x }
19 end
20 end
21
22 T.new
23 GC.start
24
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment