Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/coolkit/array/remove_first.rb
Instance Method Summary collapse
-
#remove_first(item) ⇒ self
Return a copy of an array the first instance of a given item removed.
-
#remove_first!(item) ⇒ self
Remove the first instance of an item from an array.
Instance Method Details
#remove_first(item) ⇒ self
Return a copy of an array the first instance of a given item removed.
18 19 20 |
# 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) ⇒ self
Remove the first instance of an item from an array. Note: this will mutate the reciever.
7 8 9 10 11 12 |
# 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 |