Michael Koziarski wrote:
>> If you want the equivalent of after_initialize, wouldn't you want to
>> do_stuff after calling super? In any case, if you're feeling funky,
>> you can do:
>>
>> def initialize(attrs = {}, &block)
>> attrs[:funky_default] ||= 'my funky default'
>> super
>> end
>>
>> But I much prefer:
>>
>> def initialize(attrs = {}, &block)
>> super
>> self.funky_default ||= 'my funky default'
>> end
>
> Sorry, that's what I meant, if you do stuff before @attributes is
> initialized you'll get some nasty surprises. Without cases which
> can't be solved by this pattern, I'm not sure that adding a new
> callback is justified.
>
Sorry but I must respectfully disagree. This issue caused me plenty of
confusion when I started out
with rails, I've seen lots of other people being confused about it, and you
even admit here that if
you don't do it right you'll get "nasty surprises". Any good framework should
try to avoid the
potential for nasty surprises where possible.
Now, Jonathan's plugin mentioned earlier in this thread sounds like a pretty
good solution, but I
had never heard of it until now. Maybe core could consider adopting that. But,
I would say that
setting default values for model objects is an *extremely* common practice...
needed on just about
every project. It seems like one way or another it would be nice to help rails
developers avoid some
gotchas with something that's completely straightforward in most other
languages/frameworks.
Ben
--~--~---------~--~----~------------~-------~--~----~
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 [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-core?hl=en
-~----------~----~----~----~------~----~------~--~---