title: Rails Model method check if field nil, if so return empty string
body: <p>In my model class I have a method:</p>
  
  <pre><code>def full_address
      address_lines = [self.address1,self.address2,self.address3].reject!(&amp;:empty?).join(',')
      fulladdress = address_lines + ", " + self.city + ', ' + self.state  + ', ' + self.zipcode
      return fulladdress 
  end
  </code></pre>
  
  <p>This is just an easy way to return all the address fields to view them quickly.</p>
  
  <p>This returns <code>undefined method 'empty?' for nil:NilClass</code>when its empty.  How can I change the method to work if all address1, address2, address3 are empty?</p>
  
  <p>I guess I'm looking for a function like:</p>
  
  <pre><code>ReturnBlankIfNilElseValue(self.address1)
  </code></pre>
  
  <p>Anything like that exist?</p>
  
  <pre><code>def full_address
      address_lines = [self.address1.to_s,self.address2.to_s,self.address3.to_s].reject!(&amp;:empty?).join(',')
      fulladdress = address_lines + ", " + self.city + ', ' + self.state  + ', ' + self.zipcode
      return fulladdress 
  end
  </code></pre>
  
  <p>This variation returns <code>no implicit conversion of nil into String</code> which is odd because in rails console i can type <code>nil.to_s</code> and get an empty string. </p>
  
  <p>I don't really want to check if each field is nil and then add to the array, i'd prefer a function that just returned empty string if it is nil.</p>
  
  <p><strong>Sorry the nil.to_s does work its the 2nd line that needed one as well.  Its working now will get rid of this.</strong></p>