Bird
0
0

Identify the error in this Ruby method definition: ```ruby def user_info(options) "User: #{options[:name]}, Age: #{options[:age]}" end puts user_info() ```

medium📝 Debug Q6 of 15
Ruby - Hashes
Identify the error in this Ruby method definition: ```ruby def user_info(options) "User: #{options[:name]}, Age: #{options[:age]}" end puts user_info() ```
ANo error, code runs fine
BMissing default value for options parameter
CMethod should not use options hash
DIncorrect hash key access syntax
Step-by-Step Solution
Solution:
  1. Step 1: Check method call without arguments

    Calling user_info() without arguments causes error because options parameter is required.
  2. Step 2: Fix by adding default empty hash

    Defining options = {} allows calling method without arguments safely.
  3. Final Answer:

    Missing default value for options parameter -> Option B
  4. Quick Check:

    Default parameter needed for optional hash [OK]
Quick Trick: Add options = {} to allow empty calls [OK]
Common Mistakes:
  • Assuming method accepts no arguments by default
  • Using wrong syntax for default parameters
  • Ignoring runtime error on missing argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes