From: Tony Arcieri Date: 2009-06-12T03:31:44+09:00 Subject: Re: require_all 1.0.0: A wonderfully simple way to load your code --0016e64616e6f88513046c16bab4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Wed, Jun 10, 2009 at 12:11 PM, Joel VanderWerf 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 --0016e64616e6f88513046c16bab4--