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?

2 Answers 2

2

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

puts "%10s" % ["foo"]  # => "       foo"
puts "%-10s" % ["bar"] # => "foo       "
Sign up to request clarification or add additional context in comments.

Comments

1

You can use rjust or ljust.

"123".rjust(10, '0')
#=> "0000000123"
"123".ljust(10, '0')
#=> "1230000000"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.