Skip to content

Instantly share code, notes, and snippets.

View ramoncaldeira's full-sized avatar

Ramon Caldeira ramoncaldeira

View GitHub Profile
UNITS = Hash[(1..9).zip %w(um dois tres quatro cinco seis sete oito nove)]
SPECIAL = Hash[(11..19).zip %w(onze doze treze quatorze quinze dezesseis dezessete dezoito dezenove)]
DOZENS = Hash[(1..9).zip %w(dez vinte trinta quarenta cinquenta sessenta setenta oitenta noventa)]
def to_words(number)
return SPECIAL[number] if number.between?(11, 19)
dozens, units = number.divmod(10)
[DOZENS[dozens], UNITS[units]].compact.join(' e ')
end