On Feb 24, 2008, at 3:54 PM, furtive.clown / gmail.com wrote:
> I have a simple example from my own experience.  In one project I had
> a bewildering number of property sets which needed to be added,
> subtracted, or'd, and and'ed with each other every which way.  I began
> using a Set class but it quickly became too cumbersome, as many of my
> definitions used hash literals.  Inserting +,-,&,| methods into the
> Hash class was a tremendous help: using these operations with Hash
> literals GREATLY improved readability and maintainability.

You describe one leading cause of monkeypatching--missing  
functionality in the core classes.
Here is another example:

class Object
   def singleton_class   # or meta_class or eigen_class or ...
     (class <<self; self; end)
   end
end

Matz & company have done a great job tending to the core classes but  
there are idioms in the wild that are not yet incorporated into the  
'official' releases.

I know of two ad-hoc attempts to organize common library idioms:  
Facets and Rails ActiveSupport, there are probably others.  But even  
these attempts are problematic:

Facets defines Hash#- based on [key,value] pairs and not keys.  An  
argument can be made for either approach but you can't integrate code  
bases that have different expectations for Hash#-.
Active Support defines Array#in_groups_of, which is close to  
Enumerator#each_slice but not quite the same.

There is a tension between the timely incorporation of idioms into  
the standard distribution and maintaining some overall architectural  
structure to the libraries.  Some idioms just won't fit.


Gary Wright