我知道这可能很简单,但我在一个文件中保存了一些数据:
Artichoke
Green Globe, Imperial Star, Violetto
24" deep
Beans, Lima
Bush Baby, Bush Lima, Fordhook, Fordhook 242
12" wide x 8-10" deep
我希望能够格式化成一个漂亮的 TSV 类型的表格,看起来像这样:
Name | Varieties | Container Data
----------|------------- |-------
some data here nicely padded with even spacing and right aligned text
最佳答案
试试 String#rjust(width)
:
"hello".rjust(20) #=> " hello"
https://stackoverflow.com/questions/603047/