Bird
0
0

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📝 Application Q15 of 15
Ruby - Basics and Runtime
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?
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
D<!-- Squares a number -->
Step-by-Step Solution
Solution:
  1. Step 1: Identify proper Ruby documentation comment style

    Ruby uses single-line comments with tags like @param and @return to document methods clearly.
  2. 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.
  3. Final Answer:

    # This method squares a number # @param num [Integer] the number to square # @return [Integer] the squared result -> Option B
  4. Quick Check:

    Use # with @param and @return for Ruby docs [OK]
Quick Trick: Use # with @param and @return to document Ruby methods [OK]
Common Mistakes:
MISTAKES
  • Using multi-line comments without tags for documentation
  • Using comment styles from other languages
  • Not specifying input/output clearly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes