Tutorial by Examples

Monkey patching's main issue is that it pollutes the global scope. Your code working is at the mercy of all the modules you use not stepping on each others toes. The Ruby solution to this is refinements, which are basically monkey patches in a limited scope. module Patches refine Fixnum do ...
It's a good practice to scope patches using Refinements, but sometimes it's nice to load it globally (for example in development, or testing). Say for example you want to start a console, require your library, and then have the patched methods available in the global scope. You couldn't do this wit...
Refinements have special limitations. refine can only be used in a module scope, but can be programmed using send :refine. using is more limited. It can only be called in a class/module definition. Still, it can accept a variable pointing to a module, and can be invoked in a loop. An example show...

Page 1 of 1