Last active
January 3, 2016 22:12
-
-
Save ka8725/983d497767d25dc3fd66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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