J
jdonnell
is there a way for an object to tell you where it was created a la
stacktraces?
I tried to hack it in myself, but it's really slowwwwwww. Here was my
hack attempt. I also wanted each object to tell me the time it was
created which works fine.
class Object
attr_accessor :mp_created_at
attr_accessor rigin_trace
end
class Class
alias oldNew new
def new(*args, &block)
obj = oldNew(*args, &block)
begin
raise "force a stack trace"
rescue Exception => err
obj.origin_trace = err.backtrace
end
#a hack that I need for a reason which I haven't taken the time to
figure out
obj.mp_created_at = Time.now() unless obj.frozen?
return obj
end
end
stacktraces?
I tried to hack it in myself, but it's really slowwwwwww. Here was my
hack attempt. I also wanted each object to tell me the time it was
created which works fine.
class Object
attr_accessor :mp_created_at
attr_accessor rigin_trace
end
class Class
alias oldNew new
def new(*args, &block)
obj = oldNew(*args, &block)
begin
raise "force a stack trace"
rescue Exception => err
obj.origin_trace = err.backtrace
end
#a hack that I need for a reason which I haven't taken the time to
figure out
obj.mp_created_at = Time.now() unless obj.frozen?
return obj
end
end