End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
OptionParser::Switch#summarize
summarize(sdone = {}, ldone = {}, width = 1, max = width - 1, indent = "") { |indent| ... }
lib/optparse.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/optparse.rb, line 603
def summarize(sdone = {}, ldone = {}, width = 1, max = width - 1, indent = "")
sopts, lopts = [], [], nil
@short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
@long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
return if sopts.empty? and lopts.empty? # completely hidden
left = [sopts.join(', ')]
right = desc.dup
while s = lopts.shift
l = left[-1].length + s.length
l += arg.length if left.size == 1 && arg
l < max or sopts.empty? or left << +''
left[-1] << (left[-1].empty? ? ' ' * 4 : ', ') << s
end
if arg
left[0] << (left[1] ? arg.sub(/\A(\[?)=/, '\1') + ',' : arg)
end
mlen = left.collect {|ss| ss.length}.max.to_i
while mlen > width and l = left.shift
mlen = left.collect {|ss| ss.length}.max.to_i if l.length == mlen
if l.length < width and (r = right[0]) and !r.empty?
l = l.to_s.ljust(width) + ' ' + r
right.shift
end
yield(indent + l)
end
while begin l = left.shift; r = right.shift; l or r end
l = l.to_s.ljust(width) + ' ' + r if r and !r.empty?
yield(indent + l)
end
self
end
Produces the summary text. Each line of the summary is yielded to the block (without newline).
sdone-
Already summarized short style options keyed hash.
ldone-
Already summarized long style options keyed hash.
width-
Width of left side (option part). In other words, the right side (description part) starts after
widthcolumns. max-
Maximum width of left side -> the options are filled within
maxcolumns. indent-
Prefix string indents all summarized lines.