Rails 列表有 .first 和 .second —— 有 .hundredth 或 .sixty_nineth 吗? [英] Rails lists have .first and .second – is there a .hundredth or .sixty_nineth ?

查看:38
本文介绍了Rails 列表有 .first 和 .second —— 有 .hundredth 或 .sixty_nineth 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails 是否有一个类或其他扩展允许比系列中的前几个元素(和最后一个)更多的元素?这些工作:

Is there a class or other extension for Rails that allows more than the first few elements in a series (and the last)? These work:

[2,45,2,14,53,23,634,346,34,46,643,634,346,34,34].fifth
# -> 53
[2,45,2,14,53,23,634,346,34,46,643,634,346,34,34].last
# -> 34

那么在哪里?

list.sixth
list.hundredth 

推荐答案

Rails 曾经添加过这些,但是有很多 争议 所以大部分都被删除了.这个实验的唯一残余是Array#forty_two:

There was a time when Rails added these, but there was a lot of controversy so most were removed. The only remnant of this experiment is Array#forty_two:

(1..100).to_a.forty_two
# => 42

这篇关于Rails 列表有 .first 和 .second —— 有 .hundredth 或 .sixty_nineth 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆