From: Damphyr Date: 2003-04-04T08:25:25+09:00 Subject: Plugins (sort off) Well I *am* new to Ruby, been playing around for about three weeks now (well, whenever I can think after work anyway) and while playing around I put together a very primitive (in my opinion) way of making plugins. Well calling it plugins probably is the wrong thing to do - let's say that I like distributing my code in small files all over the place because I hate scrolling and I like putting it together again programmatically. It was usefull for what I'm building (a dyndns refresh utility) but I want to ask for your ideas on how to do this better (especially on clean-up). Here's the deal: By convention I define a directory (say ./lib, where . is the installation directory of the app - find me a way to always calculate it correctly - wherever the script is called - and I will be happy) where I dump my "plugins". What the so called "plugin" is, is actually a file (with a pick-and-choose extension, call it .module) with Ruby code in it. Needs to be well formed, and not be a class or module definition (I'm not sure about that, I haven't tried it actually). What I actually do, is define a method in there like this: def detect() #some really nifty stuff end In the actual app I read all files in the ./lib directory with a .module extension and use the filenames as the "plugin" names. So each file is a way of detection (to use the semantics of my utility) that defines a detect() method and in the app I have a method that reads the file and builds a module out of it. def address(methodname) #blabla #construct the full pathname to the module file (fullname) if @methods.include?(fullname) #@methods is just an array where the contents of ./lib were read cntnt=IO.readlines(fullname).join IPDetector.module_eval(cntnt)#IPDetector is the app rtrn = detect() else raise IPDetectorError,"Unsupported method \"#{methodname}\"!" end return rtrn end Now, this works, but if I call address a couple of times with the different methods I'll end up with a couple of anonymous modules. Is there any way to clean them up? Some way to remove a mixin from a class? From what I saw in Module the method I would use ( Module#remove_method ) is private so no cleaning up. It would be nice to find a way to remove the module - then I can define constants in the module file without fear of redefinitions. (Should not forget: I'm still using Ruby 1.6.8) This whole thing is rather slow - but some kind of module pooling can be done if I use an empty class (just like in the module_eval example ) for every module file and keep them around, tracking which modules have been created. Any comments? V.- -- http://www.freemail.gr - ������ �������� ������������ ������������.