Derek
Derek

Reputation: 12378

How to write Ruby hash with list keys in YAML?

Say I have:

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

How do I represent the above hash in YAML such that YAML.load_file('that_file') will load the h hash correctly?

Upvotes: 0

Views: 132

Answers (1)

michal.samluk
michal.samluk

Reputation: 352

You can use to_yaml method to preview this:

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

Upvotes: 2

Related Questions