Skip to content

Instantly share code, notes, and snippets.

@afcapel
Created October 4, 2012 21:16
Show Gist options
  • Save afcapel/3836513 to your computer and use it in GitHub Desktop.
Save afcapel/3836513 to your computer and use it in GitHub Desktop.
Encoding text to ASCII with custom fallbacks
# encoding: utf-8
substitutions = Proc.new do |c|
case c
when 'ñ' then 'n'
when 'í' then 'i'
else '?'
end
end
puts 'Las castañas son asín o asá'.encode('ASCII', invalid: :replace, crlf_newline: true, fallback: substitutions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment