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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jonathan R. (Guest)
on 2008-11-11 00: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.
Frederick C. (Guest)
on 2008-11-11 00:47
(Received via mailing list)
On 10 Nov 2008, at 22:22, Jonathan R. 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
This topic is locked and can not be replied to.