Which of the following is a valid method name in Ruby?
easy📝 Conceptual Q2 of 15
Ruby - Methods
Which of the following is a valid method name in Ruby?
A2times
Btimes 2
Ctimes2
Dtimes-2
Step-by-Step Solution
Solution:
Step 1: Check Ruby method naming rules
Method names must start with a letter or underscore and can include letters, numbers, and underscores.
Step 2: Evaluate each option
2times starts with a number (invalid). times2 starts with a letter and includes a number (valid). times-2 contains a hyphen (invalid). times 2 contains a space (invalid).
Final Answer:
times2 -> Option C
Quick Check:
Method names start with letter or underscore [OK]
Quick Trick:Method names cannot start with numbers or contain spaces [OK]
Common Mistakes:
Starting method name with a number
Using spaces in method names
Using special characters like hyphens
Master "Methods" in Ruby
9 interactive learning modes - each teaches the same concept differently