Ruby Forum Ruby on Rails > override [] and []= on an ActiveRecord

Posted by Jonathan Rochkind (jrochkind)
on 10.11.2008 23:22
Okay, I finally figured out what was going on with my mysterious
migrate-to-Rails2 problem.

In Rails 1.x, I got away with over-riding [] and []= on an
ActiveRecord::Base model class. This made for some very convenient
coding, which is now littered all over my application.

In Rails2, you apparently can't do this.

Should I assume this is right, rather than a bug? Should it be
documented anywhere?

Still trying to think through the best least painful way to refactor my
code.
Posted by Frederick Cheung (Guest)
on 10.11.2008 23:47
(Received via mailing list)
On 10 Nov 2008, at 22:22, Jonathan Rochkind wrote:

> Should I assume this is right, rather than a bug? Should it be
> documented anywhere?

[]and []= have (as far as I can remember) allowed you to access
attributes (and are documented as such). Overriding public AR methods
is always going to be risky as you may not be the only using them -
Active Record itself may well be using them.
>
> Still trying to think through the best least painful way to refactor  
> my
> code.
What was your definition of []/[]= ?

Fred