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

New Alexandria picture New Alexandria · Oct 11, 2011 · Viewed 21.8k times · Source

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

so where is?

list.sixth
list.hundredth 

Answer

tadman picture tadman · Oct 11, 2011

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