27
Is there a built-in way to delete a value from an array, based on a block condition returning true, and return the value that was deleted?
This is a simplified version of what I'm trying to do, but it seems like there has to be a better way:
array = [1,2,3,4,5,6,7,8,9,10]
index = array.index {|v| v == 5} # returns index if block is true
value = array.delete_at(index) # deletes and returns element at index
value is then 5