【发布时间】:2012-02-14 10:14:21
【问题描述】:
我有一个字符串数组,我想将其转换为特定格式。例如
y = ["hello","how","you"]
并且输出应该是以下确切的字符串
[["hello","hello"],["how","how"],["you","you"]]
我目前使用了以下对我来说效果很好的方法,但我需要知道在 Ruby 中是否有更好的方法来做到这一点
"[#{y.collect {|x| "[#{["\"#{x}\"", "\"#{x}\""].join(",")}]" }.join(",").to_s}]"
【问题讨论】:
标签: ruby arrays string enumeration collect