-
Notifications
You must be signed in to change notification settings - Fork 22
Horizontal Rules and Vertical Space
Wes Bailey edited this page Jul 21, 2017
·
5 revisions
A common task is to create a horizontal rule with a string:
puts '-------------------------------------------------'
This works but how it is hard to read and work with. Ruby allows for a more compact syntax:
puts '-' * 80
In this case we are not solving a huge problem but a common one when writing scripts that involve formatting. Suppose we want to create a horizontal rule with some blank space to follow as shown below:
puts '=' * 60
puts "\n\n\n\n"
The above works but doesn't really tell the next developer your intentions. Using command line reporter the above is written:
horizontal_rule width: 60, color: 'red'
vertical_spacing 4
The above reads like english instead of requiring the developer to mentally parse the string in the puts statement.
-
horizontal_rule(hash)
- :char - The character used to build the rule. Default: '-'
- :width - The width in characters of the rule. Default: 100
- :color - The color to use for the terminal output i.e. 'red' or 'blue' or 'green'
- :bold - true|false to boldface the font
-
vertical_spacing(int)
- Number of blank lines to output. Default: 1