Hi -- On Tue, 21 Jul 2009, Frederick Cheung wrote:
> > > On Jul 21, 12:02 am, "David A. Black" <[email protected]> wrote: >> You can do this and get, by coincidence, something like the desired >> effect: >> >> def x=(val) >> super >> # do other stuff >> end >> >> because the call to super will trigger AR::B#method_missing, but the >> more I look at it and play around with it, the more I think it's way >> too fragile and too closely couple to the method_missing >> implementation to use. > > I haven't actually tried this but it looks like activerecord won't > generate an accessor if the method already exists (see > define_attribute_methods in activerecord/lib/active_record/ > attribute_methods.rb It won't, but super triggers method_missing anyway because the method is defined in the subclass, not in AR::Base itself. So every call to x= goes back to method_missing, decides it's not really missing, etc. There's also something going on with private that I haven't quite figured out. If I do this: private def x=(val) super end etc., then when I do obj.x=("y"), I don't get an error; it just bypasses the private version of the method and hits AR::B#method_missing, as if the private method didn't exist. I think. Anyway -- more than enough reason to avoid the whole thing. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) Training! Intro to Ruby, with Black & Kastner, September 14-17 (More info: http://rubyurl.com/vmzN) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

