According to Wikipedia, a monkey patch1 is:
a way to extend or modify the runtime code of dynamic languages […]
without altering the original source code.
The following statement from the same entry confused me:
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.
I would like to know the exact meaning of monkey patching in Ruby. To be
more specific, I would like to know the answers to the following
questions:
1- What does “runtime code” refer to in Ruby?
2- Are “monkey patching” and “open classes” different terms for the same
thing?
3- Is the following considered as monkey patching, or is it something
else?
class String
def foo
“bar”
end
end
Regards,
Yaser S.
P.S. I originally posted this question on stackoverflow2. There are
some
good
answers over there, but I’m still kinda confused. I hope that someone in
the
Ruby
community can clarify this issue for me.