我有一个这样的 YAML 文件:
options:
some_option: 'foo'
我将其作为 hash 加载yaml
,我希望能够使用它include?
来获取一个布尔值,告诉它是否存在密钥。
要获取 的子键options
,我通常会使用yaml["options"]["some_option"]
,但是如何确定 YAML 哈希是否包含["options"]["some_option"]
?你不能做这样的事情:
if yaml.include? "options"["some_option"] # or
if yaml.include? ["options"]["some_option"] # or even
if yaml.include? yaml["options"]["some_option"]
有没有办法检索options
YAML 哈希中的子键?