If I have an array of strings in ruby and I want to get the resulting array, what is the best way of doing it?
array = ["string_apple", "string_banana", "string_orange"]
desired_result = [["string", "apple"], ["string", "banana"], ["string", "orange"]]
My current attempt:
array.map(|r| r.split("_"))
map. . Note that it doesn't change the array. Maybe you just need to assign it to a variable.new_array = array.map { |r| r.split("_") }or if you want to use the same variable namearray = array.map {|r| r.split("_") }.map(|r| r.split("_")). Language Rust has that syntax.