1

I want to create a table:

Iterations                      Value
         1                      123  
         2                      124
        ..                      
       100                      124212
       101                      1242142

If I'm able to do so, do you know which website for reference is good for Ruby?

codeforester
  • 39,467
  • 16
  • 112
  • 140
Jack Smother
  • 207
  • 1
  • 8
  • 32

2 Answers2

2

Already asked here: Is there a Ruby equivalent to the C++ std::setw(int) function?

puts "%10s" % ["foo"]  # => "       foo"
puts "%-10s" % ["bar"] # => "foo       "
Community
  • 1
  • 1
LukeS
  • 481
  • 4
  • 14
1

You can use rjust or ljust.

"123".rjust(10, '0')
#=> "0000000123"
"123".ljust(10, '0')
#=> "1230000000"
oldergod
  • 15,033
  • 7
  • 62
  • 88