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
Thus [] works for an empty sequence, "" works for an empty string, and {} works for an empty mapping. Many parsers are still on YAML 1.1; this is probably what Wikipedia is talking about.
In YAML, Array represents a single key mapped to multiple values. Each value starts with a hyphen - symbol followed by space. In a single line, write the same thing above using 'square brackets syntax. '
To create an empty array, you can use an array initializer. The length of the array is equal to the number of items enclosed within the braces of the array initializer. Java allows an empty array initializer, in which case the array is said to be empty.
You can use ~ or null . Show activity on this post. If you want an empty string, rather than a null value, you can use two single quotes.
Try using []
, like:
empty_array: []
So in Ruby you have:
x = YAML::load("empty_array: []")
x # => {"empty_array" => []}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With