Bird
0
0

You want to create two Ruby methods: one that checks if an array is empty, and another that empties the array. Which method names follow Ruby conventions?

hard📝 Application Q8 of 15
Ruby - Methods
You want to create two Ruby methods: one that checks if an array is empty, and another that empties the array. Which method names follow Ruby conventions?
Aempty and clear
Bempty! and clear?
Cis_empty and clear_array!
Dempty? and clear!
Step-by-Step Solution
Solution:
  1. Step 1: Identify predicate method naming

    Methods that check a condition should end with ?, so empty? is correct.
  2. Step 2: Identify mutating method naming

    Methods that modify the object should end with !, so clear! is correct.
  3. Step 3: Evaluate options

    empty? and clear! correctly uses empty? and clear!. Other options misuse suffixes or use non-conventional names.
  4. Final Answer:

    empty? and clear! -> Option D
  5. Quick Check:

    Predicate ends with ?, mutator ends with ! [OK]
Quick Trick: Check methods end with ?, mutators with ! [OK]
Common Mistakes:
  • Swapping ? and ! suffixes
  • Using non-conventional method names
  • Omitting suffixes for predicate or mutator methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes