gpt4 book ai didi

ruby-on-rails - 如何在哈希中创建哈希

转载 作者:数据小太阳 更新时间:2023-10-29 06:39:55 24 4
gpt4 key购买 nike

我如何能够在一个散列中创建一个散列,嵌套的散列有一个键来识别它。还有我在嵌套哈希中创建的元素,我怎样才能拥有它们的键

例如

test = Hash.new()

#create second hash with a name?? test = Hash.new("test1")??
test("test1")[1] = 1???
test("test1")[2] = 2???

#create second hash with a name/key test = Hash.new("test2")???
test("test2")[1] = 1??
test("test2")[2] = 2??

谢谢

最佳答案

Joel's 是我会做的,但也可以这样做:

test = Hash.new()
test['test1'] = Hash.new()
test['test1']['key'] = 'val'

关于ruby-on-rails - 如何在哈希中创建哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6442473/

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