From: Jason Roelofs Date: 2008-05-17T03:47:15+09:00 Subject: Re: Monkey Patching (definition)? On 5/16/08, 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? > > How would you call this style of programming? I'm asking because I'm quite > new to Ruby and currently trying to learn the right vocabulary to easily > communicate with other Ruby programmers. I am definitely not looking for > flame war! > > Best regards, > Christoph Schiessl > > That's really just open classes. The term Monkey Patching comes into play when you're doing the same with classes you haven't written or don't have control over, say String or Array. class Array def my_method puts "hi" end end array = [] array.my_method # => "hi" Jason