加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 包括Enumerable的要求

发布时间:2020-12-17 02:53:40 所属栏目:百科 来源:网络整理
导读:我一直在尝试设计我的只读数组数据结构,我真的很喜欢用Enumerable类提供遍历选项,但我找不到它的要求.在我看过的一些例子中,C实现寻找#each方法,但在我看来它还不够. 解决方法 从 Pickaxe p. 474以及 the core documentation: The class [mixing in Enumera
我一直在尝试设计我的只读数组数据结构,我真的很喜欢用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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读