Skip to content

Instantly share code, notes, and snippets.

@stefanluptak
Created May 24, 2010 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanluptak/411597 to your computer and use it in GitHub Desktop.
Save stefanluptak/411597 to your computer and use it in GitHub Desktop.
class String
# "Příšerně žluťoučký kůň úpěl ďábelské ódy".strip_diacritics =>
# "Priserne zlutoucky kun upel dabelske ody"
def strip_diacritics
self.mb_chars.normalize(:kd).to_s.gsub(/[^\x00-\x7F]/, '')
end
# Little hacks to allow using also decimal comma (used in EU) not only decimal point
# "3,75".to_d => 3.75
# "3,75".to_f => 3.75
alias_method :original_to_d, :to_d
def to_d
gsub(/,/, ".").original_to_d
end
alias_method :original_to_f, :to_f
def to_f
gsub(/,/, ".").original_to_f
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment