如何在YAML中创建一个空数组?

时间:2022-06-27 07:22:11
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.

有没有方法可以指定empty_array:是否有一个数组没有元素,比如with []?当我将它加载到一个ruby散列时,我希望它知道它是一个数组。

Thanks

谢谢

1 个解决方案

#1


200  

Try using [], like:

试着用[],比如:

empty_array: []

So in Ruby you have:

在Ruby中

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

#1


200  

Try using [], like:

试着用[],比如:

empty_array: []

So in Ruby you have:

在Ruby中

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