This set of Ruby Programming Multiple Choice Questions & Answers (MCQs) focuses on “Comments in Ruby”.
1. Why do we use comments?
a) For later use to understand the working of the program
b) It is an efficient way of programming
c) It makes easy for the third person to understand
d) All of the mentioned
View Answer
Explanation: It is the efficient way of programming and easy to understand.
2. Which of the following type of comments are valid in ruby?
a) Single line comments
b) Multi line comments
c) Double line comments
d) All of the mentioned
View Answer
Explanation: Double line comments comes under multiline comment.
3. How to comment multiple lines in ruby?
a) Using multiline comments
b) Using single line comments
c) No option to comment
d) All of the mentioned
View Answer
Explanation: Multiple lines can be commented using multiline comments.
4. How to comment a single line?
a) Using #
b) Using begin and end
c) Using //
d) None of the mentioned
View Answer
Explanation: Use # to comment single line.
5. This the right way to comment a single line.
“Ruby”.length # I’m a single line comment!
a) True
b) False
View Answer
Explanation: We use # in a single line comment.
6. What is the output of the given code?
“Ruby”.length #to find the length of given string
a) 4 to find the length of given string
b) 4
c) To find the length of given string
d) Ruby
View Answer
Explanation: It finds the length of string.
7. The following syntax is used for multiline comment.
=begin
iam in a multi line comment
=end
a) True
b) False
View Answer
Explanation: We use =begin and =end to mark the beginning and end of the comment.
8. The following is the correct way to use multiline comment.
= begin # comment = end
a) True
b) False
View Answer
Explanation: No space should be given between = and begin and = or end.
9. Why do we use =begin and =end?
a) To mark the start and end of multiline comment
b) To comment multiple lines
c) To avoid the use of # again and again
d) All of the mentioned
View Answer
Explanation: Easier way to comment multiple lines.
10. What is the output of the given code?
"Ruby Language".length =begin calculate length =end
a) 13
b) 13 calculate length
c) 12
d) None of the mentioned
View Answer
Explanation: Calculate the length and is commented using =begin and =end.
Output: 13
11. What is the output of the given code?
"Ruby Language".length = begin calculate length = end
a) 13
b) 12
c) Error
d) None of the mentioned
View Answer
Explanation: No space between = and begin and end
Output: Syntax error, unexpected '=', expecting $end = begin
12. Space between 2+5 or 2 + 5 is valid but =begin and = begin is not valid.
a) True
b) False
View Answer
Explanation: Ruby recognizes =begin and = begin in different way.
Sanfoundry Global Education & Learning Series – Ruby Programming.
To practice all areas of Ruby Programming, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Programming Internship
- Practice Programming MCQs
- Check Information Technology Books
- Check Ruby Programming Books