Ruby/Array/delete

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

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

Array.delete takes a block.

month_a = %w[ nil jan feb mar apr may jun jul aug sep oct nov dec ] 
month_a.delete("noon") {"noon wasn"t found."}



delete method removes a matching object from an array, returning the deleted object if found.

month_a = %w[ nil jan feb mar apr may jun jul aug sep oct nov dec ] # => ["nil","jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]
# The following call deletes the string nil from month_a:
month_a.delete "nil"