<s>
Monkey	B-Application
patching	I-Application
is	O
a	O
technique	O
used	O
to	O
dynamically	O
update	O
the	O
behavior	O
of	O
a	O
piece	O
of	O
code	O
at	O
run-time	O
.	O
</s>
<s>
A	O
monkey	B-Application
patch	I-Application
(	O
also	O
spelled	O
monkey-patch	B-Application
,	O
MonkeyPatch	B-Application
)	O
is	O
a	O
way	O
to	O
extend	O
or	O
modify	O
the	O
runtime	O
code	O
of	O
dynamic	B-Language
languages	I-Language
(	O
e.g.	O
</s>
<s>
Smalltalk	B-Application
,	O
JavaScript	B-Language
,	O
Objective-C	B-Language
,	O
Ruby	B-Language
,	O
Perl	B-Language
,	O
Python	B-Language
,	O
Groovy	O
,	O
etc	O
.	O
)	O
</s>
<s>
The	O
term	O
monkey	B-Application
patch	I-Application
seems	O
to	O
have	O
come	O
from	O
an	O
earlier	O
term	O
,	O
guerrilla	O
patch	O
,	O
which	O
referred	O
to	O
changing	O
code	O
sneakily	O
–	O
and	O
possibly	O
incompatibly	O
with	O
other	O
such	O
patches	O
–	O
at	O
runtime	O
.	O
</s>
<s>
The	O
word	O
guerrilla	O
,	O
nearly	O
homophonous	O
with	O
gorilla	B-Application
,	O
became	O
monkey	O
,	O
possibly	O
to	O
make	O
the	O
patch	O
sound	O
less	O
intimidating	O
.	O
</s>
<s>
Despite	O
the	O
name	O
's	O
suggestion	O
,	O
the	O
"	O
monkey	B-Application
patch	I-Application
"	O
is	O
sometimes	O
the	O
official	O
method	B-Language
of	O
extending	O
a	O
program	O
.	O
</s>
<s>
For	O
example	O
,	O
web	O
browsers	O
such	O
as	O
Firefox	B-Application
and	O
Internet	B-Application
Explorer	I-Application
used	O
to	O
encourage	O
this	O
,	O
although	O
modern	O
browsers	O
(	O
including	O
Firefox	B-Application
)	O
now	O
have	O
an	O
official	O
extensions	O
system	O
.	O
</s>
<s>
In	O
Ruby	B-Language
,	O
Python	B-Language
,	O
and	O
many	O
other	O
dynamic	B-Language
programming	I-Language
languages	I-Language
,	O
the	O
term	O
monkey	B-Application
patch	I-Application
only	O
refers	O
to	O
dynamic	O
modifications	O
of	O
a	O
class	O
or	O
module	O
at	O
runtime	O
,	O
motivated	O
by	O
the	O
intent	O
to	O
patch	O
existing	O
third-party	O
code	O
as	O
a	O
workaround	O
to	O
a	O
bug	O
or	O
feature	O
which	O
does	O
not	O
act	O
as	O
desired	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
Zope	B-Language
and	O
Plone	B-Language
,	O
security	O
patches	O
are	O
often	O
delivered	O
using	O
dynamic	O
class	O
modification	O
,	O
but	O
they	O
are	O
called	O
hot	O
fixes	O
.	O
</s>
<s>
Monkey	B-Application
patching	I-Application
is	O
used	O
to	O
:	O
</s>
<s>
Replace	O
methods	B-Language
/	O
classes	O
/	O
attributes	B-General_Concept
/	O
functions	O
at	O
runtime	O
,	O
e.g.	O
</s>
<s>
Apply	O
the	O
result	O
of	O
a	O
patch	O
at	O
runtime	O
to	O
the	O
state	O
in	O
memory	B-General_Concept
,	O
instead	O
of	O
the	O
source	O
code	O
on	O
disk	B-Device
;	O
</s>
<s>
Distribute	O
security	O
or	O
behavioural	O
fixes	O
that	O
live	O
alongside	O
the	O
original	O
source	O
code	O
(	O
an	O
example	O
of	O
this	O
would	O
be	O
distributing	O
the	O
fix	O
as	O
a	O
plugin	O
for	O
the	O
Ruby	B-Application
on	I-Application
Rails	I-Application
platform	O
)	O
;	O
</s>
<s>
Malicious	O
,	O
incompetently	O
written	O
,	O
and/or	O
poorly	O
documented	O
monkey	B-Application
patches	I-Application
can	O
lead	O
to	O
problems	O
:	O
</s>
<s>
For	O
this	O
reason	O
monkey	B-Application
patches	I-Application
are	O
often	O
made	O
conditional	O
,	O
and	O
only	O
applied	O
if	O
appropriate	O
.	O
</s>
<s>
If	O
two	O
modules	O
attempt	O
to	O
monkey	B-Application
patch	I-Application
the	O
same	O
method	B-Language
,	O
one	O
of	O
them	O
(	O
whichever	O
one	O
runs	O
last	O
)	O
"	O
wins	O
"	O
and	O
the	O
other	O
patch	O
has	O
no	O
effect	O
,	O
unless	O
monkey	B-Application
patches	I-Application
are	O
written	O
with	O
a	O
pattern	O
like	O
alias_method_chain	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
Linux	B-Application
kernel	O
detects	O
proprietary	O
and	O
other	O
third-party	O
modules	O
such	O
as	O
the	O
Nvidia	O
driver	O
,	O
which	O
tamper	O
with	O
kernel	O
structures	O
,	O
so	O
that	O
developers	O
will	O
not	O
waste	O
their	O
time	O
trying	O
to	O
debug	O
a	O
problem	O
that	O
they	O
cannot	O
fix	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
in	O
2009	O
,	O
Giorgio	B-Operating_System
Maone	I-Operating_System
,	O
developer	O
of	O
NoScript	B-Operating_System
,	O
attacked	O
the	O
Adblock	B-Application
Plus	I-Application
extension	O
for	O
Firefox	B-Application
,	O
adding	O
exceptions	O
so	O
that	O
advertisements	O
on	O
his	O
own	O
websites	O
would	O
work	O
.	O
</s>
<s>
The	O
following	O
Python	B-Language
example	O
monkey-patches	B-Application
the	O
value	O
of	O
Pi	O
from	O
the	O
standard	O
Python	B-Language
math	O
library	O
to	O
make	O
it	O
compliant	O
with	O
the	O
Indiana	O
Pi	O
Bill	O
.	O
</s>
