+ 1
Centered output in console
I want that the ouput from something similar like "puts" or "print" is centered in the console. i currently havn't found a method or command for this in the internet. So: is there somethinglike this in Ruby and when yes, how I do that?
1 Resposta
+ 4
s = "dragoncreator"
puts s.center(40) # can be modified to any value depending on the width of the console
http://www.java2s.com/Code/Ruby/String/Centerleftjustifyandrightjustifystring.htm
Edit: Just found out. It can also be done using printf,
s = "dragon"
printf "%24s\n", s