Method: Thor::Shell::Basic#print_in_columns
- Defined in:
- lib/thor/shell/basic.rb
#print_in_columns(array) ⇒ Object
Prints values in columns
Parameters
Array[String, String, …]
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/thor/shell/basic.rb', line 137 def print_in_columns(array) return if array.empty? colwidth = (array.map { |el| el.to_s.size }.max || 0) + 2 array.each_with_index do |value, index| # Don't output trailing spaces when printing the last column if ((((index + 1) % (terminal_width / colwidth))).zero? && !index.zero?) || index + 1 == array.length stdout.puts value else stdout.printf("%-#{colwidth}s", value) end end end |