Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/memory_leak_helper.rb

Overview

Hack the ‘Class’-class in order to get callbacks when objects are created.

Instance Method Summary collapse

Instance Method Details

#__memory_leak_helper_original_newObject

Alias the original new-method to a method that hopefully will never be found.



87
# File 'lib/memory_leak_helper.rb', line 87

alias __memory_leak_helper_original_new new

#new(*args, &blk) ⇒ Object

Make a new method that will be called whenever an object is created. Register that object with ‘Memory_leak_helper’ and return it as it normally would.



90
91
92
93
94
95
96
# File 'lib/memory_leak_helper.rb', line 90

def new(*args, &blk)
  mlh = Memory_leak_helper::INSTANCE
  obj = __memory_leak_helper_original_new(*args, &blk)
  mlh.register_object(:obj => obj, :caller => caller) if mlh
  
  return obj
end