Skip to content

Instantly share code, notes, and snippets.

@kingsleyh
Created January 22, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingsleyh/e00be6f62a10598e10d6dd50d9b25c41 to your computer and use it in GitHub Desktop.
Save kingsleyh/e00be6f62a10598e10d6dd50d9b25c41 to your computer and use it in GitHub Desktop.
ensure_ascii_compatible_encoding
def ensure_ascii_compatible_encoding(string, options = nil)
if string.encoding.ascii_compatible?
string
else
string.encode(Encoding::UTF_8, options || {:invalid => :replace, :undef => :replace})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment