DZone 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
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
Snippets Manager replied on Thu, 2008/12/11 - 11:21pm
class String def escape_single_quotes self.gsub(/'/, "\\\\'") end endSnippets Manager replied on Mon, 2012/05/07 - 2:16pm