June 2007
Intermediate to advanced
294 pages
8h 6m
English
For this example, we’ll write a converter script. This time, instead of converting currencies, we’ll convert units for other real-world factors like length, mass, temperature, and so on. The version that I show here only handles temperatures, but you can download units_converter.rb at this book’s companion website; it is a more comprehensive script that also handles length, volume, and mass. We’ll concentrate on converting to and from English and metric units, but we’ll also support kelvins. Let’s take a look.
#!/usr/bin/env ruby # temperature_converter.rb # See also GNU units at http://www.gnu.org/software/units/units.html # Converts Metric/SI <-> English units. =begin rdoc Converts ...
Read now
Unlock full access