Rails lists have .first and .second – is there a .hundredth or .sixty_nineth ?

谁说胖子不能爱 提交于 2019-11-30 16:58:02

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

You can just use square brackets:

list[6]
list[100]

In activesupport, it does monkey patching few of these methods into Array class. If you really want more, you can take a look how to implement from activesupport:

https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/array/access.rb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!