Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.