0
0
Rubyprogramming~5 mins

Split and join methods in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AComma
BPeriod
CWhitespace (spaces, tabs, newlines)
DNo separator, returns whole string in array
What will "one two three".split return?
AError
B["one two three"]
C["o", "n", "e"]
D["one", "two", "three"]
What does ["a", "b", "c"].join return?
A"a,b,c"
B"abc"
C"a b c"
DError
Which method would you use to turn a string into an array?
Asplit
Bjoin
Cmap
Dselect
Which method would you use to combine an array of strings into one string?
Ajoin
Bsplit
Creduce
Dflatten
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.