Project

General

Profile

Bug #15613 ยป enum-chain-lambda-15613.patch

jeremyevans0 (Jeremy Evans), 08/28/2019 11:45 PM

View differences:

enumerator.c
2859 2859
    return enum_chain_size(obj);
2860 2860
}
2861 2861

  
2862
static VALUE
2863
enum_chain_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(_, block))
2864
{
2865
    return rb_funcallv(block, id_call, argc, argv);
2866
}
2867

  
2868 2862
static VALUE
2869 2863
enum_chain_enum_no_size(VALUE obj, VALUE args, VALUE eobj)
2870 2864
{
......
2896 2890
    enums = objptr->enums;
2897 2891
    block = rb_block_proc();
2898 2892

  
2899

  
2900 2893
    for (i = 0; i < RARRAY_LEN(enums); i++) {
2901 2894
        objptr->pos = i;
2902
        rb_block_call(RARRAY_AREF(enums, i), id_each, argc, argv, enum_chain_yield_block, block);
2895
        rb_funcall_with_block(RARRAY_AREF(enums, i), id_each, argc, argv, block);
2903 2896
    }
2904 2897

  
2905 2898
    return obj;
test/ruby/test_enumerator.rb
811 811
      e5.inspect
812 812
    )
813 813
  end
814

  
815
  def test_chain_each_lambda
816
    c = Class.new do
817
      include Enumerable
818
      attr_reader :is_lambda
819
      def each(&block)
820
        return to_enum unless block
821
        @is_lambda = block.lambda?
822
      end
823
    end
824
    e = c.new
825
    e.chain.each{}
826
    assert_equal(false, e.is_lambda)
827
    e.chain.each(&->{})
828
    assert_equal(true, e.is_lambda)
829
  end
814 830
end
815
-