Skip to content

Instantly share code, notes, and snippets.

@radiospiel
Created September 12, 2011 12:31
Show Gist options
  • Save radiospiel/1211147 to your computer and use it in GitHub Desktop.
Save radiospiel/1211147 to your computer and use it in GitHub Desktop.
Better warning for calling Object#id (because it includes a backtrace)
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