Building A Well Formed Number Handling Class From Scratch
Over on the Ruby Best Practices blog, Robert Klemme walks through the process of building a new numeric class from scratch in Ruby - taking into account all the gotchas and considerations that pop up along the way. Robert's task is harder and more involved than you'd initially suspect.!
Robert chooses to build a
HexNum class that can represent integers that are then displayed as hex numbers. There are considerations to be made with handling conversions from existing numeric types and his new
HexNum class, conversions to other types, supporting standard comparison methods, and overloading.
All of the above concerns are covered in the post with all the quality and detail you should expect from the RBP blog by now. This post in particular should prove interesting to most Ruby developers who feel happy digging deep (no, this isn't an article for beginners!).