Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print Horizontal Line in Ruby

Can ruby's puts or print draw horizontal line kind of like bash does with printf+tr does ?

printf '%20s\n' | tr ' ' -

this will draw:

--------------------
like image 550
Tux Avatar asked Apr 26 '26 09:04

Tux


2 Answers

You can use the following snippet

puts "-"*20

Check this for more help.

You might be interested in formatting using ljust, rjust and center as well.

like image 157
Anshul Goyal Avatar answered Apr 29 '26 04:04

Anshul Goyal


I use a quick puts "*"*80 for debug purposes. I'm sure there are better ways.

like image 28
MegaTux Avatar answered Apr 29 '26 04:04

MegaTux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!