え??PureRubyで正規表現を使わずに文字列へ3桁毎にカンマを??
RUBY_VERSION
=> "2.5.3"
p 1234567.to_s.reverse.chars.each_slice(3).map(&:join).join(',').reverse
# => "1,234,567"
p 1234567.to_s.chars.reverse_each.each_slice(3).map(&:join).join(',').reverse
# => "1,234,567"
class String
def recursive
return self if self.size <= 3
self[0..-4].recursive + ',' + self[-3, 3]
end
end
1234567.to_s.recursive
# => "1,234,567"
なんの変哲もなくてすまん