Padding printed output of tabular data

2020-07-05 05:28发布

I know this is probably dead simple, but I've got some data such as this in one file:

Artichoke

Green Globe, Imperial Star, Violetto

24" deep

Beans, Lima

Bush Baby, Bush Lima, Fordhook, Fordhook 242

12" wide x 8-10" deep

that I'd like to be able to format into a nice TSV type of table, to look something like this:

    Name  | Varieties    | Container Data
----------|------------- |-------
some data here nicely padded with even spacing and right aligned text 

7条回答
放荡不羁爱自由
2楼-- · 2020-07-05 06:18

Try String#rjust(width):

"hello".rjust(20)           #=> "               hello"
查看更多
登录 后发表回答