Tony Arcieri
6/11/2009 6:32:00 PM
[Note: parts of this message were removed to make it a legal post.]
On Wed, Jun 10, 2009 at 12:11 PM, Joel VanderWerf
<vjoel@path.berkeley.edu>wrote:
> Hm, what about
>
> module Foo
> class HonkinBigResource
> end
>
> RESOURCE_LIST << HonkinBigResource.new
> # defer until RESOURCE_LIST defined, if necessary
>
> class Bar < Base
> # Base may be undefined, so defer loading of this file
> end
> end
>
> This could result in wasted time recreating a resource, duplicates on the
> list, etc.
>
Yes, there are potential issues with this approach if you do that sort of
thing.
The larger issues are when you use this with something like ActiveSupport
loaded which redefines const_missing on everything. This will invoke that
const_missing callback whenever it hits a missing constant, and in
ActiveSupport its const_missing handler is an absolute nightmare.
Also, all uses of defined?(SomeClass) will have more or less random results,
> won't they?
>
If you have code in the toplevel or a class/method body which is using
"defined?" then it is possible you will get nondeterministic results
depending on the order code is loaded in (i.e. there may be multiple
possible orderings which satisfy all dependencies), provided those constants
are getting defined in another file which you're pulling in through
require_all.
However, if you have a file which defines a bunch of constants (e.g. a
config file) you can just load that file first, then use require_all to pull
in the rest of your code.
The behavior of "defined?" inside of methods will work exactly as it always
did since that code isn't actually executed until the method is invoked.
--
Tony Arcieri
medioh.com