End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Gem::Text#format_text
format_text(text, wrap, indent=0)
lib/rubygems/text.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/rubygems/text.rb, line 25
def format_text(text, wrap, indent=0)
result = []
work = clean_text(text)
while work.length > wrap do
if work =~ /^(.{0,#{wrap}})[ \n]/
result << $1.rstrip
work.slice!(0, $&.length)
else
result << work.slice!(0, wrap)
end
end
result << work if work.length.nonzero?
result.join("\n").gsub(/^/, " " * indent)
end
Wraps text to wrap characters and optionally indents by indent characters