Skip to content

Instantly share code, notes, and snippets.

@lodestone
Created March 10, 2009 16:49
Show Gist options
  • Save lodestone/76979 to your computer and use it in GitHub Desktop.
Save lodestone/76979 to your computer and use it in GitHub Desktop.
array = %w[apple banana carrot]
deleted = array.inject([]) do |deleted, food|
if food == 'apple'
deleted << array.delete(food)
end
deleted
end
p array # => ["banana", "carrot"]
p deleted # => ["apple"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment