diff --git a/lib/sorted_containers/sorted_array.rb b/lib/sorted_containers/sorted_array.rb index 34442f5..1891870 100644 --- a/lib/sorted_containers/sorted_array.rb +++ b/lib/sorted_containers/sorted_array.rb @@ -620,25 +620,6 @@ def fill(*args, &block) # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/MethodLength - # Calls the block, if given, with each element of +self+; - # returns a new SortedArray containing those elements of +self+ - # for which the block returns a truthy value. - # - # If no block is given, an Enumerator is returned instead. - # - # @yield [value] The block to filter with. - # @return [SortedArray, Enumerator] The filtered array. - def select - return to_enum(:select) unless block_given? - - new_values = [] - each do |value| - new_values << value if yield(value) - end - self.class.new(new_values, load_factor: @load_factor) - end - alias filter select - # Calls the block, if given, with each element of +self+; # returns +self+ with the elements for which the block returns a truthy value. # @@ -1034,18 +1015,6 @@ def rassoc(obj) index.nil? ? nil : self[index] end - # Returns a new SortedArray whose elements are all those from +self+ for which the block returns false or nil. - # - # Returns an Enumerator if no block is given. - # - # @yield [value] The block to reject with. - # @return [SortedArray, Enumerator] The rejected array. - def reject - return to_enum(:reject) unless block_given? - - select { |value| !yield(value) } - end - # Deletes every element of +self+ for which block evaluates to true. # # Returns +self+ if any changes were made, otherwise returns +nil+. diff --git a/spec/sorted_array_spec.rb b/spec/sorted_array_spec.rb index 42f3277..f3b0e99 100644 --- a/spec/sorted_array_spec.rb +++ b/spec/sorted_array_spec.rb @@ -1030,7 +1030,7 @@ def dig(key) describe "select" do it "should return the values that meet the given criterion" do array = SortedContainers::SortedArray.new([1, 2, 3, 4, 5]) - expect(array.select { |i| i > 3 }).to eq(SortedContainers::SortedArray.new([4, 5])) + expect(array.select { |i| i > 3 }).to eq([4, 5]) end it "should return an enumerator if no block is given" do @@ -1040,7 +1040,7 @@ def dig(key) it "filter should be an alias for select" do array = SortedContainers::SortedArray.new([1, 2, 3, 4, 5]) - expect(array.filter { |i| i > 3 }).to eq(SortedContainers::SortedArray.new([4, 5])) + expect(array.filter { |i| i > 3 }).to eq([4, 5]) end end @@ -1697,7 +1697,7 @@ def dig(key) describe "reject" do it "should reject elements that meet the given criterion" do array = SortedContainers::SortedArray.new([1, 2, 3, 4, 5]) - expect(array.reject { |i| i > 3 }).to eq(SortedContainers::SortedArray.new([1, 2, 3])) + expect(array.reject { |i| i > 3 }).to eq([1, 2, 3]) end it "should not modify the original array" do