Inline Percent Operator in Ruby

ruby

A quick tip, which I hadn’t discovered even after several years of using ruby professionally - you can use the % operator as an infix operator to perform string formatting.

1
"%d%d%d-%d%d%d%d" % [8, 6, 7, 5, 3, 0, 9] == "867-5309"

It follows all the same formatting codes as the regular string format functions.


I'm looking for better ways to build software businesses. Find out if I find something.