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.

➡️ Stable 0.5x Programming Languages
4,046
Comments
20
Years Active
5
Top Authors
#5359
Topic ID

Activity Over Time

2007
6
2008
68
2009
114
2010
208
2011
207
2012
273
2013
249
2014
236
2015
210
2016
207
2017
236
2018
204
2019
242
2020
245
2021
261
2022
307
2023
285
2024
188
2025
296
2026
4

Keywords

JsonClass OO e.g f.e a.f UnboundMethod sdrinf.com JsonObject Object.new StreamingJsonClass methods method class ruby object static obj patching monkey python

Sample Comments

andreareina Apr 21, 2021 View on HN

How is this different from monkeypatching in e.g. Python, Ruby?

james2vegas Feb 7, 2015 View on HN

many languages that do OO have that; Perl, Smalltalk, Objective-C, f.e.. But this seems more like monkey-patching.

CodeWriter23 Jul 2, 2017 View on HN

What is a typical use case for dynamically adding methods to a class?

lclarkmichalek Jan 13, 2012 View on HN

A lot of languages have constructs that allow changing an attribute into a method call transparently (@property in python and D)

actionfromafar Jun 23, 2024 View on HN

It's like monkey patching in Ruby. It can be used for good and for evil.

bazoom42 Jun 1, 2023 View on HN

Monkeypatching is programatically adding a method to a class at runtime.

pjmlp Feb 10, 2020 View on HN

Agree with youAs for method_missing, what do you miss from IDynamicMetaObjectProvider and related classes?

bruceboughton Feb 9, 2010 View on HN

In C# this is called extension methods: monkey-patching (for methods) without polluting the global scope.

lnanek2 Jan 2, 2013 View on HN

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

zem Oct 19, 2025 View on HN

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.