Skip to content
Permalink
Browse files

Merge pull request #567 from kostya/count

array#count
  • Loading branch information
alex committed Mar 31, 2013
2 parents b4dc514 + 40f2d1a commit 086a2056a0dd281af2b6ebada1c5ad187cc2c7b3
Showing with 30 additions and 9 deletions.
  1. +15 −0 lib-topaz/array.rb
  2. +15 −0 lib-topaz/enumerable.rb
  3. +0 −3 spec/tags/core/array/count_tags.txt
  4. +0 −6 spec/tags/core/enumerable/count_tags.txt
@@ -320,6 +320,21 @@ def rotate(n = 1)
Array.new(self).rotate!(n)
end

def count(*args, &block)
c = 0
if args.empty?
if block
self.each { |e| c += 1 if block.call(e) }
else
c = self.length
end
else
arg = args[0]
self.each { |e| c += 1 if e == arg }
end
c
end

def shuffle!
raise RuntimeError.new("can't modify frozen #{self.class}") if frozen?
(self.length - 1).downto(1) do |idx|
@@ -171,4 +171,19 @@ def max
end
end
end

def count(*args, &block)
c = 0
if args.empty?
if block
self.each { |e| c += 1 if block.call(e) }
else
self.each { c += 1 }
end
else
arg = args[0]
self.each { |e| c += 1 if e == arg }
end
c
end
end

This file was deleted.

This file was deleted.

0 comments on commit 086a205

Please sign in to comment.
You can’t perform that action at this time.