包含 Enumerable 的要求

发布于 2024-12-28 02:40:51 字数 117 浏览 2 评论 0原文

我一直在尝试设计我的只读数组数据结构,我真的很喜欢用 Enumerable 类提供遍历选项的想法,但我找不到它的要求。在我看过的一些示例中,C 实现会查找 #each 方法,但在我看来这还不够。

I've been trying to design my read only Array data structure and I really like the idea of providing traversing options with Enumerable class, but I cannot find requirements of it. In some examples that I've looked, the C implementation looks for #each method, but it seems to me that it can't be enough.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小耗子 2025-01-04 02:40:51

来自 p。 474 以及核心文档

类[混合在Enumerable中]必须提供一个方法each,该方法
产生集合的连续成员。如果Enumerable#max
使用 minsortsort_by 时,集合中的对象
还必须实现一个有意义的 <=> 运算符,因为这些方法
依赖于集合成员之间的排序。

From Pickaxe p. 474 and also from 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文