strange complains about class being obsolete

We have some ActiveRecord (and ActiveResource) models that are subclassed using the “type” field. We would attempt to make multiple selection boxes using collection_select for them, and we would get errors about the #type method being obsolete, or worse, we’d get complaints that we couldn’t turn a class into a string.

The problem is that Rails 1.2.3 (at least, we haven’t seen this with 2.0.2) uses the ‘type’ field for subclassing, but ruby’s Object used to have a .type method, now renamed .class.

Since the ActiveRecord would synthesize the attribute accessor methods, the type method wasn’t made until runtime, and since it already exists in Object, one wasn’t synthesized.

To get around this, we added the following to our models (to the parent class):

def type self[:type] end

I tried removing this with rails 2.0.2 to generate the precise error, but it appears to be fixed. I may update this entry with the exact error by checking out some older code that uses 1.2.3.