As part of a much larger project I have made a simple gem for automatically realigning strings to an arbitrary right hand margin.

require “marginalise”

puts “This is a long string for the sake of testing the marginalise gem”.marginalise(10)

This is a

long

string

for the

sake of

testing

the

marginalise

gem

The full code is available here.

I might add more specific arguments (left and right margins) and inserting a hyphen in a phonetically sensible location in the future but don’t hold your breath.