information on how to use the comments in Ruby on a cloud


Using cloud hosting services for your business is one of the best solutions where you can easily manage and handle your website. And for this reason today a lot of people are using the cloud hosting service, moreover using cloud hosting services for your website gives you more advantages where you can easily access to your data and files at any place at any time via internet. Today cloud server is the ultimate on-demand, self-service infrastructure platform. Today many IT leaders have realized the benefits of cloud-based storage, backup, and disaster recovery solutions, and for this reason, most of the IT leaders are suggesting to go with cloud server hosting solution.


But today if you are using a cloud server for your website and if you are looking for an information on how to use the comments in Ruby then here is the complete information on it. Comments are lines in computer programs that are hidden by compilers and editors. Basically, you can make use of that comments for other users/ programmers to understand by using them to provide more information about a program that they are doing.


Cloud Hosting Plans

MEDIUM CLOUD
9571 Save 44%
5360 / month
7.4 / hour
  • Disk Space : 80 GB SSD
  • 4 Core
  • RAM : 8 GB
  • Bandwidth : 5 TB
SMALL CLOUD
6929 Save 44%
3880 / month
5.3 / hour
  • Disk Space : 80 GB SSD
  • 2 Core
  • RAM : 6 GB
  • Bandwidth : 5 TB
MICRO CLOUD
4786 Save 44%
2680 / month
3.7 / hour
  • Disk Space : 60 GB SSD
  • 2 Core
  • RAM : 4 GB
  • Bandwidth : 4 TB
LARGE CLOUD
19214 Save 44%
10760 / month
14.9 / hour
  • Disk Space : 120 GB SSD
  • 8 Core
  • RAM : 16 GB
  • Bandwidth : 6 TB
EXTRA LARGE CLOUD
38286 Save 44%
21440 / month
29.7 / hour
  • Disk Space : 320 GB SSD
  • 12 Core
  • RAM : 32 GB
  • Bandwidth : 7 TB
NANO CLOUD
2545 Save 44%
1425 / month
1.9 / hour
  • Disk Space : 50 GB SSD
  • 2 Core
  • RAM : 2 GB
  • Bandwidth : 3 TB


Here is the information on how to use the comments in Ruby on a cloud server:


>>> Comment Syntax and Usage. Comments in Ruby begins with a hash (#) and it will continue to the end of the line


# This is a comment in Ruby


>>> As the above step you can use comments to give additional detail about what's happening in each part of the code.



greetings.rb

# Display a prompt to the user

puts "Please enter your name."


# Save the input they type and remove the last character (the enter keypress)

name = gets.chop


# Print the output to the screen

puts "Hello, #{name}! I'm Rosh!"


>>> And when you type a program it repeats over a pattern and displays its contents as an HTML list, and now you can see the comments


sharks.rb

sharks = ['bulldog', 'best white', 'catfish', 'grilled', 'horn', 'requiem']


# transform each entry in the array to an HTML entity, with leading spaces and a newline.

listitems = sharks.map{ |shark| "  <li>#{shark}</li>\n"}


# Print the opening <ul>, then print the array of list items

print "<ul>\n#{listitems.join}</ul>"


>>> If you are not familiar with these no need to worry about it, there will the comments which will give you an idea of how that program work and what output you will get.


$     ruby sharks.rb


>>> Now you will see the below output


Output

 

<ul>

 <li>hammerhead</li>

 <li>great white</li>

 <li>dogfish</li>

 <li>frilled</li>

 <li>bullhead</li>

 <li>requiem</li>

</ul>


>>>   As an example take a look at how to implement 8 balls pool comments in Ruby. And the computer will give a random answer to a question you ask.


8ballspool.rb

# The Eightballs class represents the 8 balls pool.

class Eightballs


 # Set up the available choices

 def initialize

     @choices = ["Yes", "No", "All signs point to yes", "Ask again later", "Don't bet on it"]

 end


 # Select a random choice from the available choices

 def shake

   @choices.sample

 end

end


def play

 puts "Ask the 8 balls pool your question."


 # Since we don't need their answer, we won't capture it.

 gets


 # Create a new instance of the 8 balls pool and use it to get an answer.

 eightballs = Eightballs.new

 answer = eightballs.shake

 puts answer


 # Prompt to restart the game and evaluate the answer.

 puts "Want to try again? Press 'y' to continue or any other key to quit."

 answer = gets.chop


 if answer == 'y'

   play

 else

   exit

 end

end


# Start the first game.

play


>>> The main purpose of using comments is that to help the programmers.  And initially, you can write a lot of comments to help you understand on what you are dealing with. And here is the example comments that is not helpful once after to come to know about Ruby


# print "Hello Rosi" to the screen.

print "Hello World"


>>> Block of a Comments. And if you want you can also block the comments where you can explain more complicated code or code that you don’t expect the reader to be familiar with.


>>> And in the block comments each line will start with the hash mark and then followed by space for readability.


....

 # Some Rack handlers (Thin, Rainbows!) implement an extended body object protocol, however,

 # some middleware (namely Rack::Lint) will break it by not mirroring the methods in question.

 # This middleware will detect an extended body object and will make sure it reaches the

 # handler directly. We do this here, so our middleware and middleware set up by the app will

 # still be able to run.

 class ExtendedRack < Struct.new(:app)

   def call(env)

     result, callback = app.call(env), env['async.callback']

     return result unless callback and async?(*result)

     after_response { callback.call result }

     setup_close(env, *result)

     throw :async

   end

...


>>> So using block comments are great when you need to completely explain of a code language. And in Ruby, it has an alternate syntax for multi-line comments, but it is rarely used, you can check it in the below command.


multiline.rb


=begin

This is a multi-line comment.

You can use this approach to make your comments

span multiple lines without placing hash marks at the start of each

line.

=end


>>> Inline comments occur on the same line of a statement where the in the code are there. Same as other they will start with hash mark, and followed by a single whitespace character


[code]  # Inline comment about the code


>>> Inline remarks ought to be utilized sparingly, however, can be compelling for clarifying precarious or non-clear parts of the code. And if you are not using the math in your Ruby programs your collaborators will not know about the complex that will create , so you may want to include an inline comment about that:


a=Complex(4,3) # Create the complex number 4+3i


>>> Or if you want you can also use inline comments to explain the reason behind that


pi = 3.14159 # Intentionally limiting the value of pi for this program.


>>> Commenting out a code for testing, as you know that using comments as a way to document code, you can use the hash mark to comment out a code which you don't want to execute.


8ball.rb

...


 # Prompt to restart the game and evaluate the answer.

 puts "Want to try again? Press 'y' to continue or any other key to quit."

 answer = gets.chop


 if answer == 'y'

   # play

 else

   exit

 end

end

...


>>> And if you are using comments it will also let you try alternatives while you are determining how to implement a solution in your code. Not only that you can also use comments to test each approach and determine which one you like the most


sharks.rb

sharks = ["Tiger", "Great White", "Hammerhead"]


# for shark in sharks do

#  puts shark

# end


sharks.each do |shark|

 puts shark

end