Skip to content

Instantly share code, notes, and snippets.

@kirkgo
Last active December 26, 2016 16:28
Show Gist options
  • Save kirkgo/b587d9baf55e95667595 to your computer and use it in GitHub Desktop.
Save kirkgo/b587d9baf55e95667595 to your computer and use it in GitHub Desktop.
Change the upcase and downcase method of the ruby ​​String class to handle the change of accented upper and lower case letters.
class String
alias_method :old_upcase, :upcase
def upcase
self.gsub( /\303[\240-\277]/ ) do |match|
match[0].chr + (match[1] - 040).chr
end.old_upcase
end
alias_method :old_downcase, :downcase
def downcase
self.gsub( /\303[\200-\237]/ ) do |match|
match[0].chr + (match[1] + 040).chr
end.old_downcase
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment