Thursday, March 06, 2008

The Units Pipe Dream...

Much of what's driven my off-off-hours development over the last year is the architecture, design and coding of a Units Framework for Ruby. While there are a few out there, this one is different - predicated on a NumericWithUnits, units are added to Numerics transparently. They act exactly like Numerics without units, but assert their types when appropriate and handle conversions automatically, such as:

puts 5.inches + 3.feet->41 inches
puts 55.miles_per_hour.feet_second->80.666666667 ft / s
puts seconds_per_week->604800

To use them you just include the framework and everything just works. Go grab them for free at my CORI (Chunks of Ruby Infrastructure) rubyforge page:

I wrote about the development as I went along, and humble submit it for your reading pleasure at

This is just the first part of the development, however - only scalar units. I am going to add formulaic conversions (like temperature) and data-driven conversions (like currency) in the next go-round. Coming soon.

No comments: