title: Ruby iterate over a variable unless it is nil
body: <p>I would like a clean way in .html.erb to loop through a variable ONLY if the variable is not nil.</p>
  
  <p>I would like the following to execute but not if @family is nil.</p>
  
  <pre><code>&lt;% @family.children.each.with_index(1) do |family_member, index| %&gt;
      // HTML HERE
  &lt;% end %&gt;
  </code></pre>
  
  <p>I am trying to avoid doing something like this</p>
  
  <pre><code>&lt;% if @family %&gt;
     &lt;% @family.children.each.with_index(1) do |family_member, index| %&gt;
         // HTML HERE
     &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>And especially trying to avoid needing</p>
  
  <pre><code>&lt;% if @family &amp;&amp; @family.children %&gt;
        &lt;% @family.children.each.with_index(1) do |family_member, index| %&gt;
            // HTML HERE
        &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Is there a better way to do this?</p>