🕷 zenspider.com

by ryan davis



sitemap
Looking for the Ruby Quickref?

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

Published 2007-04-11 @ 15:54

Tagged toys

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