Nicely formatting output to console, specifying number of tabs

前端 未结 7 1308
盖世英雄少女心
盖世英雄少女心 2020-12-24 02:01

I am generating a script that is outputting information to the console. The information is some kind of statistic with a value. So much like a hash.

So one value\'s

7条回答
  •  离开以前
    2020-12-24 02:13

    There is usually a %10s kind of printf scheme that formats nicely.
    However, I have not used ruby at all, so you need to check that.


    Yes, there is printf with formatting.
    The above example should right align in a space of 10 chars.
    You can format based on your widest field in the column.

    printf ([port, ]format, arg...)

    Prints arguments formatted according to the format like sprintf. If the first argument is the instance of the IO or its subclass, print redirected to that object. the default is the value of $stdout.

提交回复
热议问题