Skip to content

Instantly share code, notes, and snippets.

@Nakilon
Created July 4, 2025 20:07
Show Gist options
  • Save Nakilon/d817e718bc989da70f3c21725f60b85d to your computer and use it in GitHub Desktop.
Save Nakilon/d817e718bc989da70f3c21725f60b85d to your computer and use it in GitHub Desktop.
table_print.rb
require "io/console"
def table_print target = ::STDOUT
sizes = transpose.map{ |col| col.map{ |_| _.to_s.size }.max }
sizes.max.then{ |max| sizes.map!{ |_| [max - 1, _].min } } while sizes.sum + sizes.size >= ::IO::console.winsize[1]
each{ |row| target.puts row.zip(sizes).map{ |str, size| "%-#{size}s" % ("%.#{size}s" % str) }.join(" ") }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment