title: Escape specific chars in Ruby CSV
body: <p>I am trying to escape some specific chars in Ruby for a CSV. The chars are +-@=. Here is what I have done so far :</p>
  
  <pre><code>def self.to_csv
      headers =  %w{Date_de_création Civilité Nom_complet Email Téléphone Bien Agent Utilisateur}
      CSV.generate(headers: true) do |csv|
        csv &lt;&lt; headers
        all.each do |contact|
          csv &lt;&lt; [
            contact.created_at.strftime("%d/%m/%Y"),
            contact.gender,
            contact.full_name, contact.email,
            contact.phone,
            contact.accommodation.try(:ref_agency),
            contact.agent.try(:full_name) ,
            contact.user.try(:full_name) ].map { |attribute| escape_characters_in_string(attribute) if attribute.present? }
        end
      end
    end
  
    def self.escape_characters_in_string(string)
      pattern = /[=|@|+|-]/
      string.gsub(pattern) {|match| "\\" + "#{match}"}
    end
  </code></pre>
  
  <p>The output of "Areth@+=1 Fr@nklin-1" in the CSV :</p>
  
  <pre><code>Areth\@\+\=1 Fr\@nklin\-1
  </code></pre>
  
  <p>How would I go to escape these specific chars ?</p>