What does 'Monkey Patching' exactly Mean in Ruby?

后端 未结 8 2079
半阙折子戏
半阙折子戏 2020-11-27 03:29

According to Wikipedia, a monkey patch is:

a way to extend or modify the runtime code of dynamic languages [...] without altering the original sou

8条回答
  •  遥遥无期
    2020-11-27 03:32

    The short answer is that there is no "exact" meaning, because it's a novel term, and different folks use it differently. That much at least can be discerned from the Wikipedia article. There are some who insist that it only applies to "runtime" code (built-in classes, I suppose) while some would use it to refer to the run-time modification of any class.

    Personally, I prefer the more inclusive definition. After all, if we were to use the term for modification of built-in classes only, how would we refer to the run-time modification of all the other classes? The important thing to me is that there's a difference between the source code and the actual running class.

    In Ruby, the term monkey patch was misunderstood to mean any dynamic modification to a class and is often used as a synonym for dynamically modifying any class at runtime.

    The above statement asserts that the Ruby usage is incorrect - but terms evolve, and that's not always a bad thing.

提交回复
热议问题