Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Escape single quotes in Ruby strings (See related posts)

class String
  def escape_single_quotes
    self.gsub(/[']/, '\\\\\'')
  end
end


Useful if you ever get the idea of shoving Ruby strings into JavaScript code.

Comments on this post

technoweenie posts on Nov 09, 2005 at 22:05
In rails you have escape_javascript()

http://rails.rubyonrails.com/classes/ActionView/Helpers/JavaScriptHelper.html#M000440

You need to create an account or log in to post comments to this site.


Click here to browse all 5137 code snippets

Related Posts