#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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.