Monkeypatching and Dynamic Methods
The cluster focuses on monkeypatching, dynamically adding methods to classes at runtime, and equivalents like extension methods or method_missing, with comparisons across languages such as Ruby, Python, C#, and others, including use cases and metaprogramming.
Activity Over Time
Top Contributors
Keywords
Sample Comments
How is this different from monkeypatching in e.g. Python, Ruby?
many languages that do OO have that; Perl, Smalltalk, Objective-C, f.e.. But this seems more like monkey-patching.
What is a typical use case for dynamically adding methods to a class?
A lot of languages have constructs that allow changing an attribute into a method call transparently (@property in python and D)
It's like monkey patching in Ruby. It can be used for good and for evil.
Monkeypatching is programatically adding a method to a class at runtime.
Agree with youAs for method_missing, what do you miss from IDynamicMetaObjectProvider and related classes?
In C# this is called extension methods: monkey-patching (for methods) without polluting the global scope.
It isn't so odd in Ruby. Ruby has always been a duck typing land. If it quacks, it is a duck. There's even a method missing handler so you can respond to any method call whatsoever. People can and do add methods directly to even built-in classes as well, the equivalent of modifying the class prototype in Javascript. So method calls are considered more messages in Ruby and saying a class will respond differently to a message after it has more data about what it is, a certain blog for example, isn
you can view it as serving the same role as universal function call syntax, the latter being a feature in some other languages that rewrites `a.f(x)` to `f(a, x)` if `a` doesn't have a method `f`. in ruby you can just add the method to `a`'s class directly, but the idea is the same - you're adding some user defined function that is closely related to the type of `a`, and you're using method call syntax because that reads nicely.