From: elbows@... (Nathan Weston) Date: 2003-12-06T04:22:03+09:00 Subject: Re: Using Modules as Decorators Asfand Yar Qazi wrote in message news:... > Nathan Weston wrote: > > Someone recently mentioned the idea of using Modules to implement the > > Decorator pattern (though I can't find the post now, so maybe I > > imagined it). > > That was me. > > However, this still doesn't solve my problem - you see, I need to also > be able to remove functionality from each object in addition to adding > it, and I don't think you can remove a module from an object once its > been added. > > Perhaps a new feature in Ruby 2 perchance? Yeah, not being able to undecorate objects is the big drawback to this approach. However, Object#dup doesn't copy singleton methods or modules included with Object#extend, so you might be able to undecorate an object by duping it. Removable modules would be cool, but it would be tricky because modules can use append_features and extend_object to perform arbitrary transformations. Nathan