=begin
This is a multi-line comment
# Another comment line
=end
puts "Done"
medium
A. =begin and =end must be at the start of the line
B. The # inside multi-line comment causes error
C. Missing closing =end
D. Multi-line comment syntax is correct
Solution
Step 1: Check multi-line comment syntax rules
In Ruby, =begin and =end must be at the start of the line with no leading spaces.
Step 2: Analyze the given code
If =begin or =end are indented or not at line start, Ruby raises a syntax error.
Final Answer:
=begin and =end must be at the start of the line -> Option A
Quick Check:
Multi-line comment markers must start line [OK]
Hint: =begin and =end must start the line exactly [OK]
Common Mistakes:
Indenting =begin or =end
Thinking # inside multi-line comment causes error
Forgetting to close multi-line comment
5. You want to document a Ruby method that takes a number and returns its square. Which comment style best describes the method's purpose and input/output?
hard
A. =begin
Squares a number
Input: num
Output: squared number
=end
B. # This method squares a number
# @param num [Integer] the number to square
# @return [Integer] the squared result
C. // Squares a number
// Input: num
// Output: squared number
Ruby uses single-line comments with tags like @param and @return to document methods clearly.
Step 2: Compare options
# This method squares a number
# @param num [Integer] the number to square
# @return [Integer] the squared result uses Ruby documentation style. =begin
Squares a number
Input: num
Output: squared number
=end uses multi-line comment but lacks tags. Options C and D use invalid comment styles for Ruby.
Final Answer:
# This method squares a number
# @param num [Integer] the number to square
# @return [Integer] the squared result -> Option B
Quick Check:
Use # with @param and @return for Ruby docs [OK]
Hint: Use # with @param and @return to document Ruby methods [OK]
Common Mistakes:
Using multi-line comments without tags for documentation
Using comment styles from other languages
Not specifying input/output clearly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.