Skip to content
Permalink
Browse files

Merge pull request #574 from kostya/one

 enumerable#one?,none?
  • Loading branch information
alex committed Apr 7, 2013
2 parents a549656 + fa913a7 commit e0a9877d278065a615a812002da23b0268974b27
Showing with 15 additions and 14 deletions.
  1. +15 −0 lib-topaz/enumerable.rb
  2. +0 −7 spec/tags/core/enumerable/none_tags.txt
  3. +0 −7 spec/tags/core/enumerable/one_tags.txt
@@ -238,4 +238,19 @@ def count(*args, &block)
end
c
end

def one?(&block)
c = 0
self.each do |e|
c += 1 if block ? yield(e) : e
end
c == 1
end

def none?(&block)
self.each do |e|
return false if block ? yield(e) : e
end
true
end
end
@@ -1,9 +1,2 @@
fails:Enumerable#none? returns true if none of the elements in self are true
fails:Enumerable#none? returns false if at least one of the elements in self are true
fails:Enumerable#none? gathers whole arrays as elements when each yields multiple
fails:Enumerable#none? with a block passes each element to the block in turn until it returns true
fails:Enumerable#none? with a block stops passing elements to the block when it returns true
fails:Enumerable#none? with a block returns true if the block never returns true
fails:Enumerable#none? with a block returns false if the block ever returns true
fails:Enumerable#none? with a block gathers initial args as elements when each yields multiple
fails:Enumerable#none? with a block yields multiple arguments when each yields multiple
@@ -1,9 +1,2 @@
fails:Enumerable#one? when passed a block returns true if block returns true once
fails:Enumerable#one? when passed a block returns false if the block returns true more than once
fails:Enumerable#one? when passed a block returns false if the block only returns false
fails:Enumerable#one? when passed a block gathers initial args as elements when each yields multiple
fails:Enumerable#one? when passed a block yields multiple arguments when each yields multiple
fails:Enumerable#one? when not passed a block returns true if only one element evaluates to true
fails:Enumerable#one? when not passed a block returns false if two elements evaluate to true
fails:Enumerable#one? when not passed a block returns false if all elements evaluate to false
fails:Enumerable#one? when not passed a block gathers whole arrays as elements when each yields multiple

0 comments on commit e0a9877

Please sign in to comment.