你会得到你想要的YAML.
但是你的字符串有点问题.YAML希望逗号背后有空格.所以我们需要这个
str = "[[this, is], [a, nested], [array]]"
码:
require 'yaml' str = "[[this, is],[a, nested],[array]]" ### transform your string in a valid YAML-String str.gsub!(/(\,)(\S)/, "\\1 \\2") YAML::load(str) # => [["this", "is"], ["a", "nested"], ["array"]]