#39 Numbers by Name (to_lang.rb)

In previous scripts, notably #16 Adding Commas to Numbers (commify.rb) on page 75 and #17 Roman Numerals (roman_numeral.rb) on page 81, we talked about how numbers can be represented in a variety of ways. Both of those scripts showed meaningful ways of representing Integers as Strings, other than the handy but trivially different to_s method. This script, to_lang.rb, extends that discussion by representing Integers as Strings consisting of how those numbers are spoken in two real-world languages: English and Spanish.

The Code

This code is broken into three separate files, for reasons that I will make clear in How It Works on page 198.

representable_in_english.rb

  =begin rdoc
  This is intended for use with to_lang.rb ...

Get Ruby by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.