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: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 77c5e205bcb5
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 62d6dba8d763
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 9, 2013

  1. Copy the full SHA
    d91ca5a View commit details
  2. Copy the full SHA
    62d6dba View commit details
Showing with 42 additions and 23 deletions.
  1. +2 −4 corelib/enumerable.rb
  2. +35 −19 spec/rubyspec/core/enumerable/count_spec.rb
  3. +5 −0 spec/rubyspec/core/enumerable/find_spec.rb
6 changes: 2 additions & 4 deletions corelib/enumerable.rb
Original file line number Diff line number Diff line change
@@ -141,11 +141,9 @@ def count(object = undefined, &block)
}
var proc = function() {
var value;
var param = arguments.length == 1 ?
arguments[0] : $slice.call(arguments);
var value, param = $slice.call(arguments);
if ((value = block(param)) === $breaker) {
if ((value = block.apply(null, param)) === $breaker) {
return $breaker.$v;
}
54 changes: 35 additions & 19 deletions spec/rubyspec/core/enumerable/count_spec.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Enumerable#count" do
before :each do
@elements = [1, 2, 4, 2]
@numerous = EnumerableSpecs::Numerous.new(*@elements)
end
ruby_version_is "1.8.7" do
describe "Enumerable#count" do
before :each do
@elements = [1, 2, 4, 2]
@numerous = EnumerableSpecs::Numerous.new(*@elements)
end

it "returns size when no argument or a block" do
@numerous.count.should == 4
end
it "returns size when no argument or a block" do
@numerous.count.should == 4
end

it "counts nils if given nil as an argument" do
EnumerableSpecs::Numerous.new(nil, nil, nil, false).count(nil).should == 3
end
it "counts nils if given nil as an argument" do
EnumerableSpecs::Numerous.new(nil, nil, nil, false).count(nil).should == 3
end

it "accepts an argument for comparison using ==" do
@numerous.count(2).should == 2
end
it "accepts an argument for comparison using ==" do
@numerous.count(2).should == 2
end

it "uses a block for comparison" do
@numerous.count{|x| x%2==0 }.should == 3
end
it "uses a block for comparison" do
@numerous.count{|x| x%2==0 }.should == 3
end

it "ignores the block when given an argument" do
@numerous.count(4){|x| x%2==0 }.should == 1
end

ruby_version_is ""..."1.9" do
it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
multi.count {|e| e == [1, 2]}.should == 1
end
end

it "ignores the block when given an argument" do
@numerous.count(4){|x| x%2==0 }.should == 1
ruby_version_is "1.9" do
it "gathers initial args as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
multi.count {|e| e == 1 }.should == 1
end
end
end
end
5 changes: 5 additions & 0 deletions spec/rubyspec/core/enumerable/find_spec.rb
Original file line number Diff line number Diff line change
@@ -48,4 +48,9 @@
fail_proc = lambda { "yay" }
@empty.find(fail_proc) {|e| true}.should == "yay"
end

it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
multi.find {|e| e == [1, 2] }.should == [1, 2]
end
end