From: Luke Kanies Date: 2006-08-02T08:29:59+09:00 Subject: Re: Strategies for autoloading ruby files ara.t.howard@noaa.gov wrote: > module Plugable > def self.included other > ... > end > end > > class MyPlugin > include Plugable > end At this point, I'm looking at creating an Autoload class, and classes wanting to autoload will create an instance: Puppet::Autoload.new(self, "puppet/type") They'll then be able to store that instance, or retrieve it from the class: Puppet::Autoload[self].load(:package) That'll handle the mechanics of the loading. I'll have an additional :loadall method that will search through $:, loading everything that matches. I want to keep the work around plugin loading -- that is, what to do with the class and how to initialize it -- in the class supporting plugins (i.e., the class with the 'new' method), because most initialization is pretty custom. I suppose I could start with a default method in a module, though; I hadn't thought much about that. A significant part of this for me is that I have lots of classes that are related to each other -- the Puppet::Type class is related to its subclasses, the Puppet::Type::Package class is related to the Puppet::Type::Package::PkgType classes (ugh, constants are hard), the 'service' class is related to each 'svctype' class, etc. Calling 'new' directly on the related class makes that relationship very explicit and pleasantly clear. > yes - i've got a fair number of class factories lying around myself. > Class.new is powerfull since you can easily parameterize your classes. I *love* Class.new and Module.new. Ruby was great before I discovered them, but with them, I'm definitely hooked. Well, Class.new and class_eval, anyway. > on a related note i used 'traits' alot with this sort of thing since it > avoids > needing to initialize all those class vars directly down the inheritence > chain. Most of the variables involved are actually class instance variables (which, I understand, others don't use that much, but which I use pervasively and could not live without). I need to just add traits into my codebase; I think it would simplify a lot of what I'm doing. /me adds one more item to the todo > i'll read over some over of you code but gotta run to get the kid... Comments, positive or negative, are always appreciated. -- Today I dialed a wrong number...The other person said, "Hello?" and I said, "Hello, could I speak to Joey?"... They said, "Uh...I don't think so...he's only 2 months old." I said, "I'll wait." -- Steven Wright --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com