Rather than monkey patching Enumerable--thereby affecting (and possibly tromping over) every object of every class that includes it--how about extending objects on a case-by-case basis?<br><br>I&#39;ve made good use of patterns like the following:
<br><br><span style="font-family: courier new,monospace;">foobar = foo.map { |f| bar(f) }.extend(Statistics)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">avg = foobar.avg
(:bam)</span><br style="font-family: courier new,monospace;"><br>(where Statistics is a mixin module that implements sum, avg, etc, which make use of the enumerable methods)<br><br>This way any function--including 3rd-party code--that returns an array or other enumerable type can be extended on-the-fly and new functions can return &quot;pre-enriched&quot; collections when appropriate.
<br><br><span style="font-family: courier new,monospace;">numbers = [5, 10, 8, 3, 6, 12].extend(System::Linq)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">numbers.where
 { |num| num % 2 == 0 }.order_by { |n| n }.each { |i| write(&quot;#{i} &quot;) }</span><br style="font-family: courier new,monospace;"><br>Brent<br><br><br><div class="gmail_quote">On Jan 21, 2008 4:57 PM, Mike Moore &lt;
<a href="mailto:blowmage@gmail.com">blowmage@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br><br><div class="gmail_quote">
<div class="Ih2E3d">On Jan 21, 2008 4:45 PM, John Messerly &lt;<a href="mailto:jomes@microsoft.com" target="_blank">jomes@microsoft.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><br></div>Yup, you need to require the assembly. If you were writing Linq in Ruby, you&#39;d have something like System.Core.rb:<br><br>module Enumerable<br> &nbsp;def order_by<br> &nbsp; &nbsp;...<br> &nbsp;end<br> &nbsp;def where
<br> &nbsp; &nbsp;...<br> &nbsp;end<br>end<br><br>... so requiring System.Core just opens up Enumerable and sticks some methods on it.<br>At least, that&#39;s been my thinking on it. </blockquote></div><div><br>I gotcha.&nbsp; So in your example 
System.Core.rb
 was monkey-patching
Enumerable.&nbsp; You weren&#39;t actually resolving those method calls to the
extension methods in the System.Linq.Enumerable class.<br>&nbsp;</div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Maybe we add an extra step like:
<br><br>require &#39;System.Core&#39;<br>include System::Linq<br><br>I&#39;m not sure how Ruby-ish that is, though.<br><div><div></div><div></div></div></blockquote></div><div><br>I agree.&nbsp; In C# you add the namespace and those extension methods are only available in that source file.&nbsp; So you have to add the namespace to each file you want to use the extension methods.&nbsp; But in Ruby once they are added to the object they are available everywhere.&nbsp; So I wonder what a Ruby-ish solution would be.&nbsp; Does anyone on the list have any suggestions how enabling extension methods could/should look?
<br>&nbsp;</div><div class="Ih2E3d"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div>- John<br><br>_______________________________________________
<br>Ironruby-core mailing list<br><a href="mailto:Ironruby-core@rubyforge.org" target="_blank">Ironruby-core@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/ironruby-core" target="_blank">http://rubyforge.org/mailman/listinfo/ironruby-core
</a><br></div></div></blockquote></div></div><br>
<br>_______________________________________________<br>Ironruby-core mailing list<br><a href="mailto:Ironruby-core@rubyforge.org">Ironruby-core@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/ironruby-core" target="_blank">
http://rubyforge.org/mailman/listinfo/ironruby-core</a><br><br></blockquote></div><br>