But just like monkey patching alias method chain got overused and its problems started to become obvious.
Ruby monkey patch private method.
Ruby does supply the private class method.
Another reason to question the def self method notation is the ability to define private and protected methods.
Therefore a monkey patch might break code which doesn t expect the extended behavior and multiple monkey patches for the same class might cause conflicts to solve these problems refinements provide a way to extend classes locally.
Patches go into lib core.
We could monkey patch array and.
Or perhaps you need to monkey patch a class you own.
A collection of helpful methods and monkey patches for arrays hash enumerables strings objects dates in ruby.
You have to know where your monkey patches live.
Monkey patching is a powerful feature of ruby however it affects globally in a program.
So you have to have a way to quickly learn those changes when you jump into a new codebase.
For example you often see monkey patches that simply add a convenience method that has no side effect.
Ruby has a very beautiful syntax and so it can be tempting to monkey patch a class to turn some ugly method call into something that is more readable.
Rearmed is a collection of plugins which are driven by making life easier coding more natural.
The method names it generates are confusing which makes errors hard to find and debug.
The difference between this library and others is that all monkey patching is performed in an opt in way because you shouldnt be using methods you dont know about anyways.
The reason your original approach doesn t work is that instead of monkey patching array class you implemented a new stylable array class note the namespace.
Alias method chain led to my first patches to gems which led to my first pull requests which led to my first open source contributions.
Range and quartiles and spread e g variance and standard deviation.
If you re running ruby 2 0 and you don t want to monkey patch array globally you could create custom class that inherits from array.
Mean median mode dispersion e g.
I mostly follow rails monkey patching convention.
This gem calculates descriptive statistics including measures of central tendency e g.