Ruby/Array/last

Материал из Wiki.crossplatform.ru

(Различия между версиями)
Перейти к: навигация, поиск

Версия 17:10, 26 мая 2010

Both first and last take integer arguments, indicating the number of elements to return

q1 = %w[ January February March ]
q1.first 2 # => ["January", "February"]
q1.last 0 # => [] not particularly useful



Get the first and last elements of an array is with the first and last methods

q1 = %w[ January February March ]
q1.first # => January
q1.last # => March