Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e4106ad7d90f
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 47f4647c8172
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Sep 18, 2014

  1. Implement Array#count instead of falling back to Enumerable#count

    This avoids iteration with #each if no arguments are given.
    jemc committed Sep 18, 2014
    Copy the full SHA
    afae918 View commit details
  2. Merge pull request #3133 from jemc/array_count

    Implement Array#count instead of falling back to Enumerable#count
    jc00ke committed Sep 18, 2014
    Copy the full SHA
    47f4647 View commit details
Showing with 12 additions and 0 deletions.
  1. +12 −0 kernel/common/array.rb
12 changes: 12 additions & 0 deletions kernel/common/array.rb
Original file line number Diff line number Diff line change
@@ -415,6 +415,18 @@ def concat(other)
concat other
end

def count(item = undefined)
seq = 0
if !undefined.equal?(item)
each { |o| seq += 1 if item == o }
elsif block_given?
each { |o| seq += 1 if yield(o) }
else
return @total
end
seq
end

def cycle(n=nil)
return to_enum(:cycle, n) unless block_given?
return nil if empty?