From: James Gray Date: 2008-02-28T00:01:38+09:00 Subject: Re: Monkeypatching is Destroying Ruby On Feb 27, 2008, at 8:38 AM, Eric Mahurin wrote: > On Wed, Feb 27, 2008 at 7:46 AM, James Gray > > wrote: > >> On Feb 24, 2008, at 10:02 PM, James Gray wrote: >> >>> On Feb 23, 2008, at 4:23 PM, Eric Mahurin wrote: >>> >>>> I usually only do monkey patching in the >>>> following cases which have no reuse: top-level script, testing, and >>>> quick hacking. >>> >>> I think it's the ideal tool for adding compatibility methods. >> >> Along these lines, I read a chapter in Design Patterns in Ruby last >> night that suggests using Ruby's open classes as one possible way to >> implement the Adapter pattern. The book includes a pretty good >> discussion of the plusses and minus to this approach and makes >> recommendations about when it's probably worth the trade-off. It's a >> good read. >> >> James Edward Gray II > > > I don't have the book. I wouldn't mind seeing the +/- list. I don't think I would do it much justice condensing it down for this email, but it basically amounted to how well you know the code you are adapting and how simple the changes are. The author felt it was probably OK if you knew the class involved well and you were just aliasing a method or two. Again though, I'm grossly simplifying here. The book also talked about adding the methods needed to the singleton class of individual objects. I thought that was an awesome twist that we probably don't consider enough. > You are talking about this, right? > > http://en.wikipedia.org/wiki/Adapter_pattern Yes. > I don't know if you can even call it the adapter pattern since you are > destroying the adaptee interface. I view it as a Ruby way to think about the problem. Don't they always say that intent is the most important aspect to the design patterns? James Edward Gray II