Pixar's Ruby Extensions
This gem defines extensions to modules and classes in Ruby's Core and Standard Library. We've put them here because we've found ourselves performing these tasks repeatedly in our code over the years and we like to stay DRY.
They are also used in our open-source projects, and those will be migrating to use this gem - also in pursuit of DRYness.
To ease troubleshooting and prevent name collisions:
-
Methods are not directly monkey-patched into the Core or StdLib classes/modules.
-
Instead they are defined in modules under
PixarRubyExtensions
with obvious namespaces, and mixed-in to the Core or StdLib classes/modules.This provides much easier debugging when there are exceptions, since the error and backtrace will indicate exactly where these methods are defined.
-
-
With only a couple of exceptions, all new method names are prefixed with
pix_
- See
PixarRubyExtensions::IPAddr::Predicates
for examples and explanation about the exceptions.
- See
Usage
To load all the extensions: require 'pixar_ruby_extensions'
To load only one: require 'pixar_ruby_extensions/integer'
Credits
- The modularization idea came from this page about responsible monkey-patching, many thanks to the author and the discussion thread.
ToDo
- Investigate re-doing all this using refinements rather than monkey-patching