What is the main advantage of using a hash as named parameters in a Ruby method?
easy📝 Conceptual Q11 of 15
Ruby - Hashes
What is the main advantage of using a hash as named parameters in a Ruby method?
AIt improves the method's execution speed significantly.
BIt forces the method to accept only one argument.
CIt makes the method call clearer by naming each argument explicitly.
DIt prevents any default values from being used.
Step-by-Step Solution
Solution:
Step 1: Understand named parameters purpose
Named parameters improve code readability by explicitly naming each argument passed to a method.
Step 2: Compare with other options
Options B, C, and D are incorrect because using a hash does not limit argument count to one, does not speed up execution notably, and does not prevent default values.
Final Answer:
It makes the method call clearer by naming each argument explicitly. -> Option C
Quick Check:
Named parameters = clearer calls [OK]
Quick Trick:Named parameters improve clarity by naming each argument [OK]
Common Mistakes:
MISTAKES
Thinking it limits arguments to one
Assuming it speeds up code
Believing it disables default values
Master "Hashes" in Ruby
9 interactive learning modes - each teaches the same concept differently