From: Sam Roberts Date: 2005-01-26T22:15:03+09:00 Subject: Re: Injecting methods from one class into another. Quoteing eero.saynatkari@kolumbus.fi, on Wed, Jan 26, 2005 at 02:05:44PM +0900: > Sam Roberts wrote: > > Quoteing eero.saynatkari@kolumbus.fi, on Wed, Jan 26, 2005 at 07:51:57AM +0900: > > Really, I just want those methods! But, there is no way to get them in > > my class other than copying, or convincing the maintainer to cut his > > class into pieces for me. Too bad. > > I can see your point: however, a circumstance like this is somewhat exceptional. I don't agree. I suggest it seems exceptional because its impossible. Looking at the larger world, copy code around is rampant, not exceptional! Its like Class being "open" in Ruby. People regularly add methods to library classes. Its a way of code-sharing, by adding your code to existing. The opposite is not possible, where you take code from the library, and add it to yours. > Usually such is not possible due to method dependencies or missing variables > or whatever. The 'proper' thing to do would be to factor out such common code > and implement a Module (e.g. Enumerable) with the desired functionality. If > you can't factor it out, it means the implementation should remain separate. Don't know why you decide "usually", you have spent a lot of time looking at the library src, and the code you copy out mostly needed small tweaks, the methods couldn't have been rebound to your classes? The proper thing is to factor the code out, sure, but its not exactly 'proper' to inject methods into the standard library, is it? And yet, it is so useful. Sam