gpt4 book ai didi

ruby - 如何使用新的哈希语法?

转载 作者:太空宇宙 更新时间:2023-11-03 17:42:21 24 4
gpt4 key购买 nike

我正在尝试使用新的哈希语法,但它不起作用。我做错了什么?

2.6.3 :151 > hash = { duplex: duplex}
=> {:duplex=>[#<Nokogiri::XML::Element:0x1e8ee04 name="duplex"....
2.6.3 :152 > hash["duplex"]
=> nil
2.6.3 :153 > hash = { "duplex" => duplex}
=> {"duplex"=>[#<Nokogiri::XML::Element:0x1e8ee04 name="duplex" ....
2.6.3 :154 > hash["duplex"]
=> [#<Nokogiri::XML::Element:0x1e8ee04 name="duplex" ....

最佳答案

"new"散列语法用于使用符号 (:key) 而非字符串('key'"key")索引散列).所以在你的情况下,使用:

> hash = { duplex: duplex}
> hash[:duplex]
[#<Nokogiri::XML::Element:0x1e8ee04 name="duplex"...

关于ruby - 如何使用新的哈希语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57071213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com