Ruby Measurements

Posted by Marc Love
on Thursday, May 31

Here’s something I’ve been working on…

Measurement.new(6,"inches") == 6.inches

2.feet + 6.inches # => == Measurement.new(2.5, "feet")
6.5.feet - 18.inches # => == Measurement.new(5, "feet")
2.feet * 4 # => == Measurement.new(8, "feet")
4.feet / 2 # => == Measurement.new(2, "feet")
4.feet / 2.feet # => == 2

2.inches > 2.centimeters #=> true
2.inches >= 2.centimeters #=> true
2.inches == 5.08.centimeters #=> true
5.inches.between?(3.inches, 6.inches) #=> true

More to come soon…

Comments

Leave a response

  1. RustinJune 13, 2007 @ 03:11 PM

    This looks like exactly what I’m looking for today. Are you still working on it?

  2. Marc LoveJune 18, 2007 @ 02:16 PM

    Rustin -

    I sure am. I’ll have it up on RubyForge in the next couple of days. I’ll make an announcement when it’s up and running.

  3. RustinJune 18, 2007 @ 10:25 PM

    Awesome! I found the RubyForge project (assuming it’s the same one) and I’ll be watching it.