lib/defcli/formatting.rb
# Fit a text in a given width (number of chars).
# @param txt [String]
# @param width [Integer] maximum width
# @return [Array] list of lines of text
Fit a text in a given width (number of chars).
Fit a text in a given width ( number of chars ) .
def fit(txt, width = 79)
        return [] if width < 1
        r = /(.{1,#{width}})(?:\s|$)/m
        txt.split("\n").map { |l| l.scan(r) }.flatten
      end
def fit ( txt , width = 79 ) return [ ] if width < 1 r = / (.{1, #{ width } })(?: \s |$) /m txt . split ( "\n" ) . map { | l | l . scan ( r ) } . flatten end
Fit a text in a given width (number of chars).
Fit a text in a given width ( number of chars ) .
# from https://stackoverflow.com/a/7567210/735926
list of lines of text
list of lines of text
Array
txt
<not_specific>
width
None
<not_specific>
None