← Back to Ruby Operators

Block Comment

The =begin and =end syntax is the way Ruby supports block comments. This type of comment isn't all that common, but you'll sometimes see it at the beginning of a file that contains a lot of opening comments.

Part of the reason this syntax isn't that common is because of its strict indentation rules. Both the =begin and =end need to be flush to the left, no indentation for those opening and closing delimiters. The comments and code that are wrapped inside, however, can be indented however you'd like.

Besides a big block of text at the beginning of a file, I've also seen this comment syntax used wrap a bunch of configuration options for a library that have reasonable defaults.

SomeLibrary.configure do |config|
  config.port = '1234'

=begin
  # defaults to active, but can be 'inactive' or 'secondary'
  config.option_a = 'active'

  # defaults to false, can override to true
  config.option_b = false
=end
end

See the Octothorpe (#) page for the standard comment syntax.

References