Created
July 4, 2025 20:07
-
-
Save Nakilon/d817e718bc989da70f3c21725f60b85d to your computer and use it in GitHub Desktop.
table_print.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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