如何在YAML中使用列表键编写Ruby哈希?

时间:2014-04-29 23:02:57

标签: ruby-on-rails ruby yaml

说我有:

h = {}
h[["one", "two"]] = "three"
# h = {["one", "two"]=>"three"}

如何在YAML中表示上述哈希,以便YAML.load_file('that_file')正确加载h哈希?

1 个答案:

答案 0 :(得分:2)

您可以使用to_yaml方法预览:

h = {}
h[["one", "two"]] = "three"
h.to_yaml
# => "---\n? - one\n  - two\n: three\n"