Ruby/Array/delete

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

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

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"