O'Reilly logo

Ruby by Example by Kevin C. Baird

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required