Ruby/Array/last

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

Перейти к: навигация, поиск

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