joestelmach.com

Active Record Object Identity Part 2

Well, it turns out that my last post was in fact fueled by my own mis-information. While browsing through David Black's Ruby For Rails book this afternoon, I stumbled upon a discussion involving the somewhat colorful history involving object identification in Ruby.

It turns out that there are actually 3 methods on the Object class used for identification.

Object#id

A more careful look at the Rdoc specifies that this method is soon to be deprecated (why didn't i see that yesterday!?) I believe that this was traditionally used for unique identification, but was found to be over-ridden too often to be reliable. Object identification is far too ubiquitous to be left into the hands of such a popular method name as id, which leads us to...

Object#__id__

This obscure looking call was added as an additional means to getting at the object id. The idea was that since the name is so obscure, it is unlikely that anyone would ever want to over-ride it (does Ruby have no concept of final!) I guess the name was too obscure to be usable though, since the next method was added later on down the road.

Object#object_id

The (hopefully) last addition to this saga which is yet another means at getting to the object id. I suppose this is the preferred method to use these days as it is left untouched by ActiveRecord.

My only question is, what happens if you over-ride all three of these?

Comments
blog comments powered by Disqus