Ruby - Comments


Advertisements

Comments are lines of annotation within Ruby code that are ignored at runtime. A single line comment starts with # character and they extend from # to the end of the line as follows −

#!/usr/bin/ruby -w
# This is a single line comment.

puts "Hello, Ruby!"

When executed, the above program produces the following result −

Hello, Ruby!

Ruby Multiline Comments

You can comment multiple lines using =begin and =end syntax as follows −

#!/usr/bin/ruby -w

puts "Hello, Ruby!"

=begin
This is a multiline comment and con spwan as many lines as you
like. But =begin and =end should come in the first line only. 
=end

When executed, the above program produces the following result −

Hello, Ruby!

Make sure trailing comments are far enough from the code and that they are easily distinguished. If more than one trailing comment exists in a block, align them. For example −

@counter      # keeps track times page has been hit
@siteCounter  # keeps track of times all pages have been hit

Useful Video Courses


Video

Learn Ruby on Rails from Scratch

46 Lectures 9.5 hours

Eduonix Learning Solutions

Video

Master Ruby on Rails - For Beginners

97 Lectures 7.5 hours

Skillbakerystudios

Video

Dissecting Ruby on Rails 5 - Become a Professional Developer

227 Lectures 40 hours

YouAccel

Video

Complete Ruby Course in Tamil

19 Lectures 10 hours

Programming Line

Advertisements