From: James Gray Date: 2008-02-25T13:02:28+09:00 Subject: Re: Monkeypatching is Destroying Ruby On Feb 23, 2008, at 4:23 PM, Eric Mahurin wrote: > On Sat, Feb 23, 2008 at 3:07 PM, Avdi Grimm wrote: > >> Hi folks, >> >> I wrote a blog post with the intentionally provocative title above, >> which can be found here: >> >> http://avdi.org/devblog/?p=18 >> > > I don't agree with the title, but I agree almost everything you said. I'm strongly feel that James Britt has the right idea about this one. We should view it as just another tool to be used where it works best and I feel there are such places. Assigning blame to a particular element of a programming language seems foolish to me. I'm pretty confident I can write some code that abuses the heck out of while loops. Should we start hating those now too? > * adding #to_* methods to String. FasterCSV adds a to_csv() method to Array. What's that likely to conflict with exactly? Other CSV libraries is the only thing I can think of. I can live with that. > 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. Say you want to write some code that works in Ruby 1.8 and 1.9, for example. You can add the methods you need from 1.9 to 1.8 classes, with checks to ensure they are only added if they don't exist already. I can't think of a better solution than that. James Edward Gray II