title: adding a hash to an array of hash if not null?
body: <p>I have a method that takes in many parameters, including attachment, which I want to include in the hash only if not null. Is there a way to write this without constructing hashes for both cases?
  My current array of hash looks like this</p>
  
  <pre><code>messagehash = [{    :from =&gt; fromhash,
                      :content =&gt; contenthash,
                      :to =&gt; tohash, 
                      :sentDate =&gt; datetime.to_i, 
                      :isPrivate =&gt; false, 
                      :sourceInboxes =&gt; [sender.email], 
                      :subject =&gt; subject}]
  </code></pre>
  
  <p>Can I add a hash to the list if the condition is met?
    Something like this maybe</p>
  
  <pre><code>if attachment
    messagehash[0].attachment = attachment_hash
  end
  </code></pre>
  
  <p>So that it can end up like this</p>
  
  <pre><code>messagehash = [{    :from =&gt; fromhash,
                  :content =&gt; contenthash,
                  :to =&gt; tohash, 
                  :sentDate =&gt; datetime.to_i, 
                  :isPrivate =&gt; false, 
                  :sourceInboxes =&gt; [sender.email], 
                  :subject =&gt; subject,
                  :attachment =&gt; attachment_hash}]
  </code></pre>