Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: Mixins for *objects*?
John Lam
4/26/2005 1:57:00 PM
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.iu...
________________________________
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 <jlam@iunknown.com> 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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Mixins for *objects*?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password