hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Everyone Thinks Numeric Suffixes Are Neat Right Now #

by why in inspect

And they are neat. It’s just one of those really simple changes to Ruby that walks the tightrope between being a very elegant addition and being not worth anyone’s time ever.

Supposedly unleashed at last RubyConf by the sublime and blemish-free Rich Kilmer, numeric suffixes took the form of methods to Fixnum. Stuff like 12.hours, which returns the number of seconds in a twelve hour period, availing you of having to use the unseemly 12 * 60 * 60. You can find this syntax in the new Rails 0.9.4.

If you like this idea, then you’ll probably dig flgr’s patch to Ruby, supplied a few weeks ago on Ruby-Core, which adds numeric literal suffixes to Ruby. His patch adds f and b suffixes to Ruby’s number parser.

 >> 5.1b
 => #<BigDecimal:812a76c,'0.51E1',8(8)>
 >> 1f
 => 1.0

The ensuing thread isn’t acknowledged by Matz, but a few ideas are kicked around for adding 45min or "10:00"pm or similiar suffixes which could make for a very friendly flavor of Ruby.

Correction: The patch was fathered by Peter Vanbroekhoven. I repeat. Peter Vanbroekhoven. Well done. Peter Vanbroekhoven.

said on 17 Jan 2005 at 17:40

The patch was not done by me. Peter did a great job on implementing my initial proposal. (I originally posted this to suby-ruby where he picked it up.)

Thanks for the publicity work. :)

said on 18 Jan 2005 at 16:34

After seeing Rich’s presentation I added “suffix” methods for RVG . These methods convert inches, centimeters, etc. to pixels, and rads and grads to degrees. Very simple, very useful.

Comments are closed for this entry.