Skip to content

Instantly share code, notes, and snippets.

@Nakilon
Created July 4, 2025 20:07
Show Gist options
  • Select an option

  • Save Nakilon/d817e718bc989da70f3c21725f60b85d to your computer and use it in GitHub Desktop.

Select an option

Save Nakilon/d817e718bc989da70f3c21725f60b85d to your computer and use it in GitHub Desktop.

Revisions

  1. Nakilon created this gist Jul 4, 2025.
    6 changes: 6 additions & 0 deletions table_print.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    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