Skip to content

Instantly share code, notes, and snippets.

@Mikoangelo
Forked from nofxx/gist:4649
Created August 9, 2008 04:35
Show Gist options
  • Save Mikoangelo/4650 to your computer and use it in GitHub Desktop.
Save Mikoangelo/4650 to your computer and use it in GitHub Desktop.
class String
ACCENTS = {
"a" => %w{ ã á â },
"e" => %w{ é ê },
"i" => %w{ í },
"o" => %w{ õ ó ô },
"u" => %w{ ú },
"c" => %w{ ç }
}
def to_ascii!
ACCENTS.each_pair do |key, val|
self.gsub!(Regexp.union(*val), key)
end
self
end
def to_ascii
dup.to_ascii!
end
end
string = "óãõáçeãúi"
string # => "óãõáçeãúi"
string.to_ascii # => "oaoaceaui"
string # => "óãõáçeãúi"
string.to_ascii! # => "oaoaceaui"
string # => "oaoaceaui"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment