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

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


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


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