On 5 May 2011, at 07:37, Fearless Fool <li...@ruby-forum.com> wrote:

> Max Schubert wrote in post #996758:
>> Fearless,
>> Well, not really a bug - it is 'behavior as designed' but it is also a
>> 'fail' for those of us using 'meta-programming as designed LOL'
>> because meta-programming requires that classes be loaded and that the
>> callbacks associated with Object and Class get called!
> 
> Now I'm intrigued, but that doesn't explain to me why
> MyModel.descendants returns a valid list of descendants on the first
> call but an empty list thereafter.  Can you explain why this happens
> (and why it's considered behavior as designed)?

descendants returns all loaded subclasses, but when class caching is off, 
classes are cleared out, so the freshly loaded copy of MyModel has no loaded 
subclasses.

About the best thing you can do is (at the bottom of the base class) use 
require_dependency to make all the subclasses be loaded when the base class is.

By design is perhaps not quite the right word - it's something people have long 
been aware, with no obvious solution, but it is obviously not desirable 
behaviour.

Fred

> 
>>> P.S.: I poked around and didn't see anything obvious
>> 
>> I am using the Google group to respond, so no handle :).  Were you
>> able to find the code I used to work around the class caching issue?
> 
> I couldn't find your code.  Without your patch, I can (a) restart the
> server frequently to avoid the MyModel.descendants bug that I observed,
> or (b) turn on class caching, which requires me to restart the server
> between changes.  So your patch would be handy.
> 
> (...I'm still astonished this is how it's designed to work!!)
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> 
> -- 
> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to