Commit 02ac5dd9 authored by Jun Hiroe's avatar Jun Hiroe

Add Enumerable#count

parent 31b2980a
......@@ -208,4 +208,22 @@ module Enumerable
a
end
end
def count(v=nil, &block)
count = 0
if block
self.each do |e|
count += 1 if block.call(e)
end
else
if v == nil
self.each { count += 1 }
else
self.each do |e|
count += 1 if e == v
end
end
end
count
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment