以有效的方式将Array数组转换为字符串数组

时间:2013-03-16 09:37:02

标签: ruby-on-rails arrays

我有一个数组

arr=[["Sumit", "where"], ["where", "are"], ["are", "you"]]

我要转换

arr=["Sumit where", "where are", "are you"]

我怎么能以有效的方式做到这一点

2 个答案:

答案 0 :(得分:2)

arr=[["Sumit", "where"], ["where", "are"], ["are", "you"]]  
v = arr.map { |x| x.join(" ") }  
p v 

答案 1 :(得分:0)

尝试:

arr=[["Sumit", "where"], ["where", "are"], ["are", "you"]]
arr = arr.map {|i| i.join(' ') }