Created
September 12, 2011 12:31
-
-
Save radiospiel/1211147 to your computer and use it in GitHub Desktop.
Better warning for calling Object#id (because it includes a backtrace)
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
module BetterObjectIdWarning | |
def self.activate | |
return if @activated | |
@activated = true | |
Object.class_eval { | |
def id | |
return object_id if @in_object_id_warning | |
@in_object_id_warning = true | |
begin | |
backtrace = caller.reject { |line| line =~ /\/gems\// }[0,8] | |
STDERR.puts "*** Calling Object#id for\n\t#{inspect}\n from\n\t#{backtrace.join("\n\t")}" | |
object_id | |
ensure | |
@in_object_id_warning = nil | |
end | |
end | |
} | |
end | |
end | |
BetterObjectIdWarning.activate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment