<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Inter-sections.net : Array matcher</title>
    <link>http://inter-sections.net/2007/11/26/array-matcher.rss</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Business, Technology, Life</description>
    <item>
      <title>Comment on Array matcher by Mark Van Holstyn</title>
      <description>&lt;p&gt;Not 100% sure I like this more or not, but what about this?&lt;/p&gt;

&lt;p&gt;ActionMailer::Base.deliveries.select do |mail|
  mail.body.match(/#{user.confirmation_code}/) &amp;amp;&amp;amp;
  mail.body.match(/#{user.id}/)
end.should&lt;em&gt;not be&lt;/em&gt;empty&lt;/p&gt;

&lt;p&gt;or, so we don&amp;#8217;t do unnecessary checks&amp;#8230;&lt;/p&gt;

&lt;p&gt;ActionMailer::Base.deliveries.detect do |mail|
  mail.body.match(/#{user.confirmation_code}/) &amp;amp;&amp;amp;
  mail.body.match(/#{user.id}/)
end.should&lt;em&gt;not be&lt;/em&gt;nil&lt;/p&gt;</description>
      <pubDate>Mon, 26 Nov 2007 22:42:34 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:5a466ec5-d3a2-4e86-bf26-d47ea044347c</guid>
      <link>http://inter-sections.net/2007/11/26/array-matcher#comment-340</link>
    </item>
    <item>
      <title>Comment on Array matcher by daniel</title>
      <description>&lt;p&gt;Interesting :-) Another twist on the approach.&lt;/p&gt;

&lt;p&gt;I like yours because it doesn&amp;#8217;t require any meta-programming, but I still think my version is more readable. Only just though&amp;#8230; I guess it&amp;#8217;s down to taste. ;-)&lt;/p&gt;

&lt;p&gt;Thanks for the comment.&lt;/p&gt;</description>
      <pubDate>Mon, 26 Nov 2007 22:49:44 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:b8e0daba-76b3-4a1f-bdf7-2cccf1760447</guid>
      <link>http://inter-sections.net/2007/11/26/array-matcher#comment-339</link>
    </item>
    <item>
      <title>Comment on Array matcher by Peter Harkins</title>
      <description>&lt;p&gt;I prefer to see blocks collect data instead of modifying external variables:&lt;/p&gt;

&lt;p&gt;module Enumerable
  def sum ; inject(0) { |x, y| x + y }; end&lt;/p&gt;

&lt;p&gt;def at&lt;em&gt;least&lt;/em&gt;one_should
    matches = self.collect do |item|
      1 if yield item
    end.compact.sum
    matches.should &amp;gt;= 1
  end
end&lt;/p&gt;

&lt;p&gt;But that&amp;#8217;s overkill to test &amp;#8220;at least one&amp;#8221;, which I&amp;#8217;d write:
module Enumerable
  def at&lt;em&gt;least&lt;/em&gt;one_should
    self.each do |item|
      return true if yield item
    end
    return false
  end
end&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not familiar with your test framework so amybe that &amp;#8216;should&amp;#8217; test is raising something or setting a variable instead of returning true/false, but I&amp;#8217;d rather express that I&amp;#8217;m trying to find at least one by returning as soon as I find one. And it saves the extra checks.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Jan 2008 22:18:15 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:ff236a00-16e6-4666-b749-6d6a88925d4d</guid>
      <link>http://inter-sections.net/2007/11/26/array-matcher#comment-341</link>
    </item>
  </channel>
</rss>
