How do I create an empty array in YAML?

RubyArraysYaml

Ruby Problem Overview


array_with_three_elements:
- 1
- 2
- 3

empty_array:

Is there any way to specify that empty_array: is an array with no elements, such as with []? When I load it into a ruby hash I'd like it to know that it's an array.

Thanks

Ruby Solutions


Solution 1 - Ruby

Try using [], like:

empty_array: []

So in Ruby you have:

x = YAML::load("empty_array: []")
x # => {"empty_array" => []}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJulian MannView Question on Stackoverflow
Solution 1 - RubymaericsView Answer on Stackoverflow