I have a string to parse. I managed to use a method to find the indices of a substring. Here's the code:
indexArray = []
myString.to_enum(:scan, /(\n)/i).map do
indexArray.push [$`.size] #`
end
#indexArray = [0,2,3,4,5,6]
myString[indexArray[1]] # => no implicit conversion of Array into Integer (TypeError)
I tried using to_i, but it seems like broken logic. Any insight is appreciated. If I uncomment the second to the last line, making indexArray an array of integers, it works. I am wondering why I can get a character at an index using a basic array, but not the array derived from this method.
indexArray.push [$`.size]pushes another array ontoindexArray, so you end up with something like[[0],[2],[3],[4],[5],[6]]. You probably wantindexArray.push $`.size.