Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #570 from kostya/array_methods
- Loading branch information
|
@@ -106,6 +106,7 @@ def compact! |
|
|
end |
|
|
|
|
|
def reject!(&block) |
|
|
return self.enum_for(:reject!) unless block |
|
|
prev_size = self.size |
|
|
self.delete_if(&block) |
|
|
return nil if prev_size == self.size |
|
@@ -248,11 +249,14 @@ def *(arg) |
|
|
end |
|
|
|
|
|
def map!(&block) |
|
|
return self.enum_for(:map!) unless block |
|
|
raise RuntimeError.new("can't modify frozen #{self.class}") if frozen? |
|
|
self.each_with_index { |obj, idx| self[idx] = yield(obj) } |
|
|
self |
|
|
end |
|
|
|
|
|
alias :collect! :map! |
|
|
|
|
|
def max(&block) |
|
|
max = self[0] |
|
|
self.each do |e| |
|
|
|
@@ -77,6 +77,8 @@ def select(&block) |
|
|
result |
|
|
end |
|
|
|
|
|
alias :find_all :select |
|
|
|
|
|
def include?(obj) |
|
|
self.each do |o| |
|
|
return true if o == obj |
|
@@ -136,6 +138,7 @@ def take(n) |
|
|
end |
|
|
|
|
|
def take_while(&block) |
|
|
return self.enum_for(:take_while) unless block |
|
|
result = [] |
|
|
self.each do |o| |
|
|
break unless yield(o) |
|
@@ -145,6 +148,7 @@ def take_while(&block) |
|
|
end |
|
|
|
|
|
def reject(&block) |
|
|
return self.enum_for(:reject) unless block |
|
|
result = [] |
|
|
self.each do |o| |
|
|
result << o unless yield(o) |
|
|
Oops, something went wrong.
|
|
@@ -1,6 +1,3 @@ |
|
|
fails:Array#map! returns an Enumerator when no block given, and the enumerator can modify the original array |
|
|
fails:Array#map! when frozen raises a RuntimeError when calling #each on the returned Enumerator |
|
|
fails:Array#map! when frozen raises a RuntimeError when calling #each on the returned Enumerator when empty |
|
|
fails:does not copy untrusted status |
|
|
fails:does not copy tainted status |
|
|
fails:returns the evaluated value of block if it broke in the block |
Oops, something went wrong.
Oops, something went wrong.
|
|
@@ -1,4 +1,2 @@ |
|
|
fails:Enumerable#find_all returns all elements for which the block is not false |
|
|
fails:Enumerable#find_all returns an enumerator when no block given |
|
|
fails:Enumerable#find_all passes through the values yielded by #each_with_index |
|
|
fails:Enumerable#find_all gathers whole arrays as elements when each yields multiple |
|
|
@@ -1,2 +1 @@ |
|
|
fails:Enumerable#reject returns an Enumerator if called without a block |
|
|
fails:Enumerable#reject gathers whole arrays as elements when each yields multiple |
Oops, something went wrong.