|
Versions Of This Snippet::
Download a raw-text version of this code by clicking on "Download Version"
Latest Snippet Version: :2.0
class Object
def commify(sep = ',')
to_s.
reverse.
gsub!(/\d{3}/){|x| x + sep}.
reverse!.
sub!(/^#{sep}/, '')
end
end
puts "1234".commify
puts 123.commify('_')
puts 123456.commify
Submit a new versionYou can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..
|
||||||||||||||||||||||||||||||||||||||||||||||
