Recall & Review
beginner
What does the
split method do in Ruby?The
split method breaks a string into an array of smaller strings based on a separator you provide. If no separator is given, it splits on whitespace by default.Click to reveal answer
beginner
How does the
join method work in Ruby?The
join method takes an array of strings and combines them into one string, inserting a separator between each element if you provide one.Click to reveal answer
beginner
Example: What is the result of
"apple,banana,carrot".split(",")?It returns the array
["apple", "banana", "carrot"] by splitting the string at each comma.Click to reveal answer
beginner
Example: What does
["red", "green", "blue"].join("-") return?It returns the string
"red-green-blue" by joining the array elements with a dash between them.Click to reveal answer
intermediate
Why are
split and join useful together?You can use
split to break a string into parts, change or process those parts, then use join to put them back together into a new string.Click to reveal answer
What is the default separator for the
split method in Ruby if none is provided?✗ Incorrect
If you don't give a separator,
split divides the string at whitespace by default.What will
"one two three".split return?✗ Incorrect
Without an argument,
split splits on spaces, so it returns an array of words.What does
["a", "b", "c"].join return?✗ Incorrect
Without a separator,
join combines elements directly with no spaces.Which method would you use to turn a string into an array?
✗ Incorrect
split breaks a string into an array based on a separator.Which method would you use to combine an array of strings into one string?
✗ Incorrect
join combines array elements into a single string.Explain how you can use
split and join together to change a sentence.Think about breaking a sentence into words, changing words, then making a new sentence.
You got /3 concepts.
Describe what happens when you call
split without any arguments on a string.What does Ruby consider whitespace?
You got /3 concepts.