From: Brad Phelan Date: 2007-07-18T04:50:14+09:00 Subject: Re: possibly bulletproof eval() Giles Bowkett wrote: >> ActiveRecord has the write_attribute and read_attribute methods >> which is a better choice for what you are doing. You can also >> use [] and []= as aliases for write_attribute and read_attribute > > It's a class method which creates new instances. I don't think you can > get to write_attribute that way, because it's a private method. > Not a problem! Just use use [] and []= public aliases for the protected methods. From the RDoc for ActiveRecord. http://ar.rubyonrails.org/classes/ActiveRecord/Base.html#M000402 Public Instance Methods ----------------------- [](attr_name) Returns the value of the attribute identified by attr_name after it has been typecast (for example, "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). (Alias for the protected read_attribute method). [ show source ] # File lib/active_record/base.rb, line 1489 1489: def [](attr_name) 1490: read_attribute(attr_name) 1491: end []=(attr_name, value) Updates the attribute identified by attr_name with the specified value. (Alias for the protected write_attribute method). [ show source ] # File lib/active_record/base.rb, line 1495 1495: def []=(attr_name, value) 1496: write_attribute(attr_name, value) 1497: end -- Brad Phelan http://xtargets.com