1
2
3
4
5
6
7
8
9
10
11
12
class MyClass
  def initialize(s)
    @s = s
    ObjectSpace.define_finalizer(self, proc { puts @s })
  end
end

MyClass.new("R.I.P.")

GC.start

# sadly, it doesn't prints the string as expected