From: Rick DeNatale Date: 2008-05-17T07:44:06+09:00 Subject: Re: Monkey Patching (definition)? On Fri, May 16, 2008 at 2:27 PM, Christoph Schiessl wrote: > For example. Look the following piece of simple Ruby Code: > > class ExampleClass > def some_instance_method > 'Called some_instace_method!' > end > end > > def ExampleClass.i_am_a_class_method > 'Called i_am_a_class_method!' > end > > inst = ExampleClass.new > def inst.i_am_an_instance_method > 'Called i_am_an_instance_method' > end > > Basically, I am reopening the definition of ExampleClass and adding another > method. At first I am creating a new class method and afterwards I am > creating a new instance method (for the object inst only). Is monkey > patching the correct term for that kind of programming style? Actually, this code never reopens the definition of ExampleClass. def ExampleClass.i_am_a_class_method end Doesn't reopen example class, it defines a method on the singleton class (a.k.a metaclass) of the object bound to the global name ExampleClass, which just happens to be a class, it doesn't really do anything to the ExampleClassObject. inst = ExampleClass.new def inst.i_am_an_instance_method end Likewise doesn't touch the ExampleClass object at all either. It adds a method to the singleton class of the object bound to the variable inst. I've skimmed the earlier responses and I don't think anyone else pointed this out. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/