gpt4 book ai didi

ruby - 包括可枚举的要求

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

我一直在尝试设计我的只读 Array 数据结构,我非常喜欢为 Enumerable 类提供遍历选项的想法,但我找不到它的要求。在我看过的一些例子中,C 实现寻找 #each 方法,但在我看来这还不够。

最佳答案

来自 Pickaxe p. 474 也来自 the core documentation :

The class [mixing in Enumerable] must provide a method each, which yields successive members of the collection. If Enumerable#max, min, sort, or sort_by is used, the objects in the collection must also implement a meaningful <=> operator, because these methods rely on an ordering between members of a collection.

关于ruby - 包括可枚举的要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8943040/

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