On 24/07/07, ara.t.howard <[EMAIL PROTECTED]> wrote: > > > On Jul 22, 2007, at 4:39 PM, Michael Koziarski wrote: > > > > > I can buy your argument, but if I do so, there doesn't seem to be a > > need for after_initialize: > > > > def initialize(attrs) > > do_stuff > > super > > end > > one other nit-pick: it's somewhat archaic and java like to > __require__ client code to call super, one slip of the keyboard and > someone is bug finding... > > it's much nicer, imho, to relieve the client code from that burden via > > class ActionRecord::Base > def self.new *args, &block > returning(allocate) do |object| > object.instance_eval do > internal_initialize *args, &block # all real work here > initialize *args, &block # default does nothing > end > end > end > end > > > basically just following the paradigm whereby designing classes that > a made to be inherited with any work in initialize is less that > ideal... food for thought.
Except that, when you're setting defaults, you really would like to interpose some behaviour between the bit that gets the object to the point where the various setter/getter methods will work and the bit where ActiveRecord calls self.attribs = ... One option would be to override ActiveRecord::Base.allocate to return an object that's been got to that point, but then you'd be doing a chunk of work that then gets thrown away whenever an object is made through AR::Base.instantiate. Sadly, initialize tends to be one of those warts on an API where you really can't get away with requiring client code to call super. You *could* add #before_initialize and #after_initialize hooks, but then we're back where we started... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---