George Moschovitis wrote:
>>Object methods do not work in vacuum, they usually use instance
>>variables to reffer to the object's state, possibly changing it
>>(remember encapsulation ;-)?). How would you expect your
>>inject_method() deal with it?
> 
> 
> I thought Ruby promotes 'duck typing'.
> 
> I would like to inject specific methods between specific classes. The
> destination class has all the instance variables needed to succesfully
> execute the method.
> 

I do not think what you want has anything to do with 'duck typing'. 
'duck typing' only means that you can send a message to any object and 
if the object has a corresponding method it gets executed regardless of 
object type. It does not urge you to abandon the "normal" way of method 
definition for a class.

In general, I am very cautious to dynamically adding methods down the 
road, as it greatly increases the risk of your system becoming 
incomprehensible.

As somebody has indicated, Ruby has other ways to "inject" methods in 
some controlled manner, like mixins or inheritance. I would consider 
them first before resorting to any sort of "tricks", even if they were 
possible (everything is possible in Ruby, you know ;-), one way or another).

Gennady.