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: 87ef3834e920
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 86bf3170ea8f
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jan 9, 2016

  1. Add spec for Enumerable#first with multiple yield parameters

    kachick authored and Yorick Peterse committed Jan 9, 2016
    Copy the full SHA
    864dd4b View commit details
  2. Fix yield parameter of Enumerable#first

    kachick authored and Yorick Peterse committed Jan 9, 2016
    Copy the full SHA
    86bf317 View commit details
Showing with 8 additions and 1 deletion.
  1. +3 −1 kernel/common/enumerable.rb
  2. +5 −0 spec/ruby/core/enumerable/first_spec.rb
4 changes: 3 additions & 1 deletion kernel/common/enumerable.rb
Original file line number Diff line number Diff line change
@@ -563,7 +563,9 @@ def find_index(value=undefined)

def first(n=undefined)
return __take__(n) unless undefined.equal?(n)
each { |element| return element }
each do
return Rubinius.single_block_arg
end
nil
end

5 changes: 5 additions & 0 deletions spec/ruby/core/enumerable/first_spec.rb
Original file line number Diff line number Diff line change
@@ -12,6 +12,11 @@
EnumerableSpecs::Empty.new.first.should == nil
end

it 'returns a gathered array from yield parameters' do
EnumerableSpecs::YieldsMulti.new.to_enum.first.should == [1, 2]
EnumerableSpecs::YieldsMixed2.new.to_enum.first.should == nil
end

it "raises a RangeError when passed a Bignum" do
enum = EnumerableSpecs::Empty.new
lambda { enum.first(bignum_value) }.should raise_error(RangeError)