Skip to content

Instantly share code, notes, and snippets.

View bernerdschaefer's full-sized avatar

Bernerd Schaefer bernerdschaefer

View GitHub Profile
@bernerdschaefer
bernerdschaefer / string.rb
Created July 5, 2012 12:48 — forked from durran/string.rb
Safe encode input strings, when they can be flagged with the wrong encoding.
class String
def force_valid_encoding
find_encoding(Encoding.list.to_enum)
end
def safe_encode(name)
force_valid_encoding
encode(name, :undef => :replace, :invalid => :replace, :replace => "")
end