Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 904 Bytes

Comments_in_Ruby.md

File metadata and controls

39 lines (26 loc) · 904 Bytes

In programming languages comments are lines of code that are ignored at runtime by the compiler or interpreter.

In Ruby both single-line and multi-line comments exist.

Singleline Comments in Ruby

A single line comment in Ruby starts with # character.

Example

# This is a single-line comment.
puts "Hello World"

The output generated by the program will be Hello World.

Multiline Comments in Ruby

You can comment multiple lines using =begin and =end syntax.

Example

=begin
This is a multiline 
comment But =begin and =end should come in the first line only. 
=end
puts "Hello World"

The output generated by the program will be Hello World.

Why to use comments in programs?

  • To add a description to the program.
  • To avoid confusion while collaboration.
  • To improve understanding of the program.
  • To avoid future errors.