#28 Converting Temperatures (temperature_converter.rb)
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.
The Code
#!/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 ...
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.