Bird
0
0

In Ruby, what is the result of calling split on the string "dog-cat-mouse" with the argument "-"?

easy📝 Conceptual Q1 of 15
Ruby - String Operations
In Ruby, what is the result of calling split on the string "dog-cat-mouse" with the argument "-"?
AAn array of strings: ["dog", "cat", "mouse"]
BA single string with dashes removed: "dogcatmouse"
CA string with dashes replaced by spaces: "dog cat mouse"
DAn error because split requires no arguments
Step-by-Step Solution
Solution:
  1. Step 1: Understand split method

    The split method divides a string into an array based on the delimiter provided.
  2. Step 2: Apply split with "-" delimiter

    Calling split("-") on "dog-cat-mouse" splits the string at each dash.
  3. Final Answer:

    ["dog", "cat", "mouse"] -> Option A
  4. Quick Check:

    Split returns an array of substrings separated by the delimiter. [OK]
Quick Trick: split returns an array split by the delimiter [OK]
Common Mistakes:
  • Thinking split removes characters without returning an array
  • Assuming split returns a string instead of an array
  • Believing split requires no arguments to work

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes