Ruby Array转换为带括号的字符串

时间:2021-06-26 21:45:35

I have an array like so: ["data","data2"]

我有一个像这样的数组:[“data”,“data2”]

What would be the most Ruby-like way to convert this into a string with brackets included: "['data','data2']"

什么是类似Ruby的方式将其转换为包含括号的字符串:“['data','data2']”

Thanks

1 个解决方案

#1


4  

I can't say how "ruby-ish" this is, but it's what I would typically do:

我不能说这是“ruby-ish”,但这是我通常会做的事情:

puts "['" + array_of_strings.join("','") + "']"

#1


4  

I can't say how "ruby-ish" this is, but it's what I would typically do:

我不能说这是“ruby-ish”,但这是我通常会做的事情:

puts "['" + array_of_strings.join("','") + "']"