Nicely formatting output to console, specifying number of tabs

前端 未结 7 1307
盖世英雄少女心
盖世英雄少女心 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:34

    There was few bugs in it before, but now you can use most of printf syntax with % operator:

    1.9.3-p194 :025 > " %-20s %05d" % ['hello', 12]
     => " hello                00012" 
    

    Of course you can use precalculated width too:

    1.9.3-p194 :030 > "%-#{width}s %05x" % ['hello', 12]
      => "hello          0000c" 
    
    0 讨论(0)
提交回复
热议问题