item 有哈希数组。前任。 item = [{item1},{item2},{item3}]
def function1
item.map( other_class.call )
end
# other class will return the array which contains string
class other_class
def call
#method which return arrray of strings
end
end
当前函数 1 正在返回具有字符串值的数组数组。
function1 output example [["str1"], [], ["str2"], ["str3"], ["str4","str5"]]
我想修改将返回字符串数组的函数 1。
expected output = ["str1" "str2", "str3", "str4", "str5"]
伙计们,知道我该如何修改上述方法。
提前致谢。
输入
item=[["str1"], [], ["str2"], ["str3"], ["str4","str5"]]
代码
p item.flatten
输出
["str1", "str2", "str3", "str4", "str5"]
所以你应该写这样的东西
def function1
other_class.call.flatten
end