Ruby/Array/first

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

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

Access the First and Last Elements of the Array

# Accessing the first and last elements of an array is easy with the first and last methods
x = [1, 2, 3]
puts x.first
puts x.last



If you pass a numeric parameter to first or last, you"ll get that number of items from the start or the end of the array

x = [1, 2, 3]
puts x.first(2).join("-")