Bird
0
0

What does the Ruby match method return when it finds a pattern in a string?

easy📝 Conceptual Q11 of 15
Ruby - Regular Expressions
What does the Ruby match method return when it finds a pattern in a string?
AA <code>MatchData</code> object containing details of the match
BThe matched substring as a string
CAn array of all matched substrings
DA boolean value true
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of match

    The match method searches a string for a pattern and returns information about the match.
  2. Step 2: Identify the return type when a match is found

    It returns a MatchData object, which holds details like matched text and position.
  3. Final Answer:

    A MatchData object containing details of the match -> Option A
  4. Quick Check:

    match returns MatchData [OK]
Quick Trick: Remember: match returns MatchData, not just string [OK]
Common Mistakes:
  • Thinking it returns just the matched string
  • Assuming it returns an array of matches
  • Believing it returns true/false

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes