0
0
Rubyprogramming~10 mins

YARD for documentation in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A# TODO: add docs
B# @param name [String] the name to greet
C# greet method
D# This method prints a greeting
Attempts:
3 left
💡 Hint
Common Mistakes
Writing a plain comment without '@param' tag
Using incorrect tag like '@argument' instead of '@param'
2fill in blank
medium

Complete 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'
A[Array] the sum of a and b
B[String] the sum of a and b
C[Integer] the sum of a and b
D[Hash] the sum of a and b
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong return type like String or Array
Omitting the return type brackets []
3fill in blank
hard

Fix 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'
Ausername
Bname
Cuser
Duser_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name in the '@param' tag
Misspelling the parameter name
4fill in blank
hard

Fill 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'
Anum
B[Integer]
CInteger
D[String]
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting brackets in '@return' tag
Using wrong parameter name
5fill in blank
hard

Fill 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'
Afirst
Blast
C[String]
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'String' without brackets in '@return'
Swapping parameter names in '@param' tags