Created
July 2, 2013 14:45
-
-
Save rlb3/5909896 to your computer and use it in GitHub Desktop.
Destructor in ruby?
This file contains hidden or 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
| #!/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