Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a YARD documentation comment for the method.
Ruby
# [1] def greet(name) "Hello, #{name}!" end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Writing a plain comment without '@param' tag
Using incorrect tag like '@argument' instead of '@param'
✗ Incorrect
The correct YARD tag for documenting a method parameter is '@param' followed by the parameter name and its type.
2fill in blank
mediumComplete the code to add a YARD documentation tag describing the return value.
Ruby
# @return [1] def add(a, b) a + b end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong return type like String or Array
Omitting the return type brackets []
✗ Incorrect
The method returns the sum of two integers, so the return type is '[Integer]'.
3fill in blank
hardFix the error in the YARD documentation tag for the method parameter.
Ruby
# @param [1] [String] the user's name def welcome(user_name) "Welcome, #{user_name}!" end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name in the '@param' tag
Misspelling the parameter name
✗ Incorrect
The parameter name in the method is 'user_name', so the '@param' tag must use the exact same name.
4fill in blank
hardFill both blanks to document a method with a parameter and a return value using YARD.
Ruby
# @param [1] [Integer] the number to double # @return [2] the doubled number def double(num) num * 2 end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting brackets in '@return' tag
Using wrong parameter name
✗ Incorrect
The parameter name is 'num' and the return type should be '[Integer]' with brackets.
5fill in blank
hardFill all three blanks to document a method with two parameters and a return value using YARD.
Ruby
# @param [1] [String] the first name # @param [2] [String] the last name # @return [3] the full name def full_name(first, last) "#{first} #{last}" end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'String' without brackets in '@return'
Swapping parameter names in '@param' tags
✗ Incorrect
The parameter names are 'first' and 'last', and the return type should be '[String]' with brackets.