Challenge - 5 Problems
YARD Documentation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this YARD documentation comment parsing?
Given the following Ruby method with YARD comments, what will be the description extracted by YARD for the method `greet`?
Ruby
## # Greets a person with their name. # # @param name [String] the name of the person # @return [String] greeting message # def greet(name) "Hello, #{name}!" end
Attempts:
2 left
💡 Hint
Look at the first comment line after the ## marker.
✗ Incorrect
YARD uses the first comment line after the ## as the method description. The @param and @return tags provide additional metadata but are not the main description.
🧠 Conceptual
intermediate1:30remaining
Which YARD tag documents the return type of a method?
In YARD documentation, which tag is used to specify what a method returns?
Attempts:
2 left
💡 Hint
It describes the output of the method.
✗ Incorrect
The @return tag documents the return value and its type for a method in YARD.
🔧 Debug
advanced2:30remaining
Why does this YARD comment fail to document the method parameter?
Examine the following YARD comment and method. Why will YARD not recognize the parameter documentation correctly?
##
# Calculates the square of a number.
# @param num the number to square
# @return [Integer] the squared result
#
def square(number)
number * number
end
Ruby
## # Calculates the square of a number. # @param num the number to square # @return [Integer] the squared result # def square(number) number * number end
Attempts:
2 left
💡 Hint
Check if the parameter names match exactly.
✗ Incorrect
YARD requires the parameter name in the @param tag to exactly match the method's parameter name to link documentation correctly.
📝 Syntax
advanced2:00remaining
Which YARD comment block is syntactically correct for documenting a method?
Choose the correctly formatted YARD comment block for this method:
def add(a, b)
a + b
end
Attempts:
2 left
💡 Hint
YARD comment blocks start with ## and each line begins with #.
✗ Incorrect
Option B uses the correct YARD syntax: a comment block starting with ## and each line starting with #, with tags properly formatted.
🚀 Application
expert3:00remaining
How many methods will YARD document in this Ruby class?
Consider this Ruby class with YARD comments. How many methods will YARD generate documentation for?
class Calculator
##
# Adds two numbers
# @param x [Integer]
# @param y [Integer]
# @return [Integer]
def add(x, y)
x + y
end
# Subtracts y from x
def subtract(x, y)
x - y
end
##
# Multiplies two numbers
# @param x [Integer]
# @param y [Integer]
# @return [Integer]
def multiply(x, y)
x * y
end
end
Ruby
class Calculator ## # Adds two numbers # @param x [Integer] # @param y [Integer] # @return [Integer] def add(x, y) x + y end # Subtracts y from x def subtract(x, y) x - y end ## # Multiplies two numbers # @param x [Integer] # @param y [Integer] # @return [Integer] def multiply(x, y) x * y end end
Attempts:
2 left
💡 Hint
YARD only documents methods with comment blocks starting with ##.
✗ Incorrect
YARD documents methods with comment blocks starting with ##. The 'add' and 'multiply' methods have such blocks, but 'subtract' only has a single # comment, so it is not documented.