I've read that it is possible to add a method to an existing object (e.g. not in the class definition) in python, I think this is called Monkey Patching (or in some cases Duck Punching). I understand that it's not always a good decision to do so. But, how might one do this?
And if you don't know python, can your language of choice do this? If so, how?
UPDATE 8/04/2008 00:21:01 EST:
That looks like a good answer John Downey, I tried it but it appears that it ends up being not a true method. Your example defines the new patch function with an argument of self, but if you write actual code that way, the now patched class method asks for an argument named self (it doesn't automagically recognize it as the identity class, which is what would happen if defined within the class definition), meaning you have to call class.patch(class) instead of just class.patch() if you want the same functionality as a true method. It looks like python isn't really treating it as a method, but more just as a variable which happens to be a function (and as such is callable). Is there any way to attach an actual method to a class?
Oh, and Ryan, that isn't exactly what I was looking for (it isn't builtin functionality), but it is quite cool nonetheless.
UPDATE 8/05/2008 22:24:01 EST:
Thank you for the well presented answer Jason Pratt, that was exactly what I was looking for.