From: John Lam Date: 2005-04-26T22:56:33+09:00 Subject: Re: Mixins for *objects*? Thanks, Austin! There's just so much to love about Ruby. This feature really blows me away. BTW, the problem domain that I'm working on is writing some Ruby wrappers to make configurating IIS easier. For anyone else interested, here's a rough sketch of the VirtualDirectory module that adds a few convenience features to ADSI programming: module VirtualDirectory def parent() return self.Parent end def wrap(obj) obj.extend(VirtualDirectory) return obj end def create(name) return wrap(self.Create('IIsWebVirtualDir', name)) end def find(name) each() { |node| return node if node.Name == 'name' } end def each() super() { |node| yield node if node['class'].to_s() == 'IIsWebVirtualDir' } end def delete() parent.Delete('IIsWebVirtualDir', self.Name) end module_function :wrap end Here's some sample usage that assumes that site points to an IIsWebServer COM object @root = VirtualDirectory.wrap(@site.GetObject('IIsWebVirtualDir', 'Root') Does this idiom make sense? Comments / criticisms more than welcome! Thanks -John http://www.iunknown.com ________________________________ From: Austin Ziegler [mailto:halostatue@gmail.com] Sent: Tue 4/26/2005 9:28 AM To: ruby-talk ML Subject: Re: Mixins for *objects*? On 4/26/05, John Lam wrote: > I'm trying to do something somewhat esoteric. I'm trying to mix in some additional functionality to WIN32OLE objects to avoid having to create a wrapper object that simply delegates functionality. > > Imagine: > > dir = WIN32OLE.connect("some moniker that returns a directory") > > Let's say that I had a class that defined some helper methods like Ruby iterators: > > class Dir > ... > end > > Is it possible to mix dir with Dir at runtime easily without adding methods at runtime etc? Try: dir = WIN32OLE.connect("some moniker that returns a directory") module Dir ... end dir.extend(Dir) -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca