I doubt I'll have another release of ZenHacks, so.... STIW4

| | Comments (4)

for apeiros:

class Numeric
  def commify(dec='.', sep=',')
    num = to_s.sub(/\./, dec)
    dec = Regexp.escape dec
    num.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*#{dec})/, "\\1#{sep}").reverse
  end
end

4 Comments

16000324.commify('.') # =>

~> -:4:in `escape': wrong number of arguments (0 for 1) (ArgumentError) ~> from -:4:in `commify' ~> from -:9

Is there a lib I need to get Regexp.escape?

doh. should be fixed.

Excellent; thanks for sharing.

Leave a comment

About this Entry

This page contains a single entry by zenspider published on April 11, 2007 3:54 PM.

Functional Test Matrix, a visualization was the previous entry in this blog.

zentest version 3.5.0 has been released! is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Pages

Powered by Movable Type 4.32-en