Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"
Add Comment
Please, Sign In to add comment