When I wrote the following code, the array of arrays came back and I was confused.
numbers.split(/,/) #=> [["1","2","3"]]
The cause was that I was calling split for a split array.
numbers = "1,2,3".split(/,/)
numbers.split(/,/) #=> [["1","2","3"]]
Rails Active Support provides Array # split. It splits an array into an array of arrays before and after a particular value.
[1, 2, 3, 4, 5].split(3) # => [[1,2],[4,5]]
However, if the variable was supposed to contain a string but was an array, it would be annoying.
def include_three?(string)
string.split(/,/).include?("3")
end
include_three?("1,2,3,4,5".split(/,/)) #=> false