R – Is monkey patching/class-reopening really an example of reflection

late-bindingmonkeypatchingoopreflectionterminology

Apologies for the recursive nature of this question but the chosen answer to a question on SO got me questioning my understanding of reflection.

I thought reflection was mainly about querying the internal happenings of a program while it's running. The example given in this response patches Ruby's built-in Integer class.

  • Isn't this more like function overloading/inheritance rather than runtime modification?
  • Is class reopening really an example of reflection?

Best Solution

Reflection can be used to implement late binding.

Late binding can be used to implement monkey patching.

Monkey patching can be used to achieve the sort of coding style shown in that answer.

But there are other ways to implement such features that don't require monkey patching, or reflection. Heck, a good macro pre-compiler could get you close.

So, technically correct, but not (IMHO) the greatest example.