Reputation: 959
I'm trying to do some string formatting. I've tried with 'insert' but that is obviously wrong. I only need the formatting.
t = 123456789
I want t to be formatted in: 1234.56.789
So, including the two dots. What is the best way to do this in Ruby?
Upvotes: 0
Views: 199
Reputation: 2679
extend the class
class String
def right_format
self.clone.insert(4,'.').insert(7,'.')
end
end
i.e. inject a method
Upvotes: 2