But there s a special multiline comment syntax.
Ruby block comment syntax.
That s exactly how to comment out a block of code in ruby.
Usr bin ruby def test yield end test puts hello world this example is the simplest way to implement a block.
The argument names are defined between two pipe characters.
The ruby single line comment begins with the character and ends at the end of the line.
Modern code editors allow you to select a block of code comment all of it using a keyboard shortcut so there is no extra effort involved.
Comments in ruby begin with a hash mark and continue to the end of the line.
Ruby blocks are little anonymous functions that can be passed into methods.
That s what block comments are for.
The character set used in the ruby source files for the current implementation is based on ascii.
You can use the hash character at the beginning of a line i am a comment.
Puts hello ruby when executed the above program produces the following result hello ruby.
You call the test block by using the yield statement.
It can occur anywhere.
It looks like this.
You can comment multiple lines using begin and end syntax as follows.
Usr bin ruby w this is a single line comment.
These longer form comments apply to some or all of the.
Here is an example.
Syntax begin rescue onetypeofexception rescue anothertypeofexception else other exceptions ensure always will be executed end.
A comment hides a line part of a line or several lines from the ruby interpreter.
Comment syntax and usage.
Any characters from the character to the end of the line are completely ignored by the ruby interpreter.
The character doesn t necessarily have to occur at the beginning of the line.
You can use block comments to explain more complicated code or code that you don t expect the reader to be familiar with.
Initializing ruby program this is main ruby program terminating ruby program ruby comments.
The case of characters in source files is significant.
Or a comment may be on the same line after a statement or expression.
Blocks are enclosed in a do end statement or between brackets and they can have multiple arguments.
We enclose the code that could raise an exception in a begin end block and use rescue clauses to tell ruby the types of exceptions we want to handle.