class Array
Public Instance Methods
remove_first(item)
click to toggle source
Return a copy of an array the first instance of a given item removed.
@param item [Object] @return [self]
# File lib/coolkit/array/remove_first.rb, line 18 def remove_first(item) return self.dup.tap { |s| s.remove_first!(item) } end
remove_first!(item)
click to toggle source
Remove the first instance of an item from an array. Note: this will mutate the reciever.
@param item [Object] @return [self]
# File lib/coolkit/array/remove_first.rb, line 7 def remove_first!(item) return self if self.length == 0 index = self.index(item) self.delete_at(index) if index return self end