diff --git a/core/src/main/ruby/jruby/kernel19/enumerable.rb b/core/src/main/ruby/jruby/kernel19/enumerable.rb index 391c7cf4375..0dc13fd8178 100644 --- a/core/src/main/ruby/jruby/kernel19/enumerable.rb +++ b/core/src/main/ruby/jruby/kernel19/enumerable.rb @@ -17,7 +17,11 @@ def slice_before(filter = (no_filter = true; nil), &block) Enumerator.new do |yielder| ary = nil - self.each do |elt| + self.each do |*elt| + if elt.size < 2 + elt = elt.size == 0 ? nil : elt[0] + end + if block if no_filter state = block.call elt diff --git a/spec/regression/GH-744_GH-264_enum_args_using_call_spec.rb b/spec/regression/GH-744_GH-264_enum_args_using_call_spec.rb index bd15e781649..be0b2711c35 100644 --- a/spec/regression/GH-744_GH-264_enum_args_using_call_spec.rb +++ b/spec/regression/GH-744_GH-264_enum_args_using_call_spec.rb @@ -325,6 +325,14 @@ def each(&block) it_behaves_like "an Enumerable method which takes a block", :array end + describe "Enumerable#slice_before" do + it "passes all #each args to its block" do + @test_enum.slice_before do |obj| + obj.should == [1, 2, 3] + end.each{} + end + end + describe "Enumerable#flat_map" do subject { :flat_map } it_behaves_like "an Enumerable method which takes a block", :first_arg