Ruby/Array/last

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

Версия от 18:00, 13 сентября 2010; ViGOur (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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