Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created March 30, 2012 11:28
Show Gist options
  • Save mahemoff/2250926 to your computer and use it in GitHub Desktop.
Save mahemoff/2250926 to your computer and use it in GitHub Desktop.
Escape HTML Entities using Ruby 1.9.2 gsub hash syntax
def escape(s)
s.gsub(/[&<>"]/, '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment