Bird
0
0

Why might using a hash as named parameters be less safe than using Ruby's keyword arguments introduced in Ruby 2.0+?

hard📝 Conceptual Q10 of 15
Ruby - Hashes
Why might using a hash as named parameters be less safe than using Ruby's keyword arguments introduced in Ruby 2.0+?
AHashes allow any keys, so typos won't raise errors
BHashes require all keys to be symbols
CHashes enforce strict type checking on values
DHashes prevent default values for parameters
Step-by-Step Solution
Solution:
  1. Step 1: Compare hashes vs keyword arguments

    Hashes accept any keys silently; typos create unexpected keys.
  2. Step 2: Understand keyword argument safety

    Keyword arguments raise errors on unknown or missing keys, preventing silent bugs.
  3. Final Answer:

    Hashes allow any keys, so typos won't raise errors -> Option A
  4. Quick Check:

    Hash keys are flexible but less safe [OK]
Quick Trick: Keyword args catch typos; hashes do not [OK]
Common Mistakes:
  • Thinking hashes enforce key types
  • Assuming hashes prevent default values
  • Believing hashes do type checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes