Ruby/Comments in Ruby

From Meshplex

Jump to: navigation, search
Image:Ruby_on_rails_tutorials.jpg
Ruby for complete beginners
Ruby Introduction
What can I use RoR for?
Reasons for choosing RoR over other popular programming languages such as php or asp.net .What makes Ruby so much more special
Where can I find RoR? In what “forms” does it come?
How to install RoR.Solutions for both the novice and professional programmers on Windows,Mac OS X and Linux.Prerequisites.
Ruby programming tutorials for beginners:
Ruby Basics
** Writing Programs in Ruby
** Ruby and the Text Editors
** Escape Character Sequence
** Ruby Arithmetic
** Comments in Ruby
** Ruby Documentation
Ruby Variables, Datatypes, Operators
Ruby Symbols
Ruby Statements
Ruby Converting data to another type: type conversion or typecasting
Ruby Arrays, Hashes, Ranges
Ruby Functions and built in functions
Ruby Control structures
Ruby Regular expressions and blocks
Ruby Loops
Ruby Recursion
Ruby Data Structures
Ruby Methods, Classes, Modules, Namespaces
Ruby Exceptions
Ruby Object Oriented Programming
Ruby Multithreading
Ruby File Handling.Input and Output
Ruby Basic GUI
Ruby and databases.Ruby on Rails and MySQL
Ruby Basic CGI.Using fastCGI
Ruby Basic Networking and web programming
Ruby Basic Graphics
Ajax and Rails.Web 2.0 and what it means
Ruby Testing, Debugging, Automation of tasks
Ruby Apache,Capistrano, Mongrel,lighttpd – reviews and tips
Finding a Ruby on Rails ready web hosting company
BONUS: mini tutorial for a simple RoR application

[edit] How to use Comments in Ruby

Comments as the term states itself are the lines which are although written with the code at the time of programming but they are always ignored at the time of execution of that code.

The basic purpose of putting these lines in the code is to make the code properly understandable and easy to trace the functionality of that code in the future by the programmers other than the originator of that code segment. It is suggested to mention the copyright, author name, filename, version number and license terms in the comment section so as to maintain the proper history and records of the code.


For example:# Copyright © 2001, Richard Willy


In Ruby the comments are extended with the symbol “#” to the end of the line.

For example:

1. # this symbol states that it is a comment.

For Example:

# This is my first Ruby program
# I am excited to learn Ruby!!
puts 'My First Ruby Program'


2. We can have comments in this way also in Ruby code.

=begin This is another way of putting document. =end

For Example:

=begin
This is my first Ruby Program
print "My First Ruby Program".
=end
puts 'My First Ruby Program'


An Example showing the implemenatation of above mentioned Comment syntax:

# This basic program Demonstrates how to
# use comments in Ruby programming
puts "john"+"David"+"Mary"
# The above code will print all names without space in between
puts "John "+"David "+"Mary "
# This will print all three names with one space in between each name.


Comment on footer of program giving details of the author of the code:

=begin
 * Name:
 * Description   
 * Author:
 * Date:
 * License:
=end


Program demonstrating implementation of comments

if b == 2
 true        # special case
else
 prime?(b)   # work only if b is odd
end
Next
Personal tools