<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Proc code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 06:11:10 GMT</pubDate>
    <description>DZone Snippets: Proc code</description>
    <item>
      <title>Rails validation for Phone</title>
      <link>http://snippets.dzone.com/posts/show/5057</link>
      <description>&lt;code&gt;&lt;br /&gt;  validates_length_of :phone, :is =&gt; 10, :message =&gt; 'must be 10 digits, excluding special characters such as spaces and dashes. No extension or country code allowed.', :if =&gt; Proc.new{|o| !o.phone.blank?}&lt;br /&gt;  validates_length_of :fax, :is =&gt; 10, :message =&gt; 'must be 10 digits, excluding special characters such as spaces and dashes. No extension or country code allowed.', :if =&gt; Proc.new{|o| !o.fax.blank?}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Jan 2008 00:38:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5057</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Too small for function, too big to be un-DRY</title>
      <link>http://snippets.dzone.com/posts/show/2503</link>
      <description>I wanted to execute the same block of code twice in the same procedure, but the block itself I did not feel warranted its own function (this was in a Rails test).  So here's a neat trick to keep it DRY:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;    &lt;br /&gt;p = Proc.new do&lt;br /&gt;  r1 = Record.find 1&lt;br /&gt;  r2 = Record.find 2&lt;br /&gt;  r3 = Record.find 3&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;p.call&lt;br /&gt;&lt;br /&gt;# ... do some useful stuff ...&lt;br /&gt;&lt;br /&gt;p.call # do it again!&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Aug 2006 01:40:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2503</guid>
      <author>garrydolley (Garry Dolley)</author>
    </item>
  </channel>
</rss>
