gpt4 book ai didi

Ruby - 如何使用 Hash#to_proc?

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

documentation是空的,但我想知道如何使用它才能知道它什么时候有用。

最佳答案

这样你就可以将哈希过程传递给 map 之类的东西。

https://bugs.ruby-lang.org/issues/11653

my_hash = ->key{{
a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
}[key]}

my_hash[:a]
# => 1

[:e, :a, :b, :f, :c, :d].map(&my_hash) # hash is now mappable
# => [5, 1, 2, 6, 3, 4]

关于Ruby - 如何使用 Hash#to_proc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38943466/

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