Skip to content

Horizontal Rules and Vertical Space

Wes Bailey edited this page Jan 29, 2012 · 5 revisions

Horizontal Rules and Vertical Space

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)
vertical_spacing(4)

The above reads like english instead of requiring the developer to mentally parse the string in the puts statement.

API Reference

  • horizontal_rule(hash)
    • :char - The character used to build the rule. Default: '-'
    • :width - The width in characters of the rule. Default: 100
  • vertical_spacing(int)
    • Number of blank lines to output. Default: 1
Clone this wiki locally