From: jakesower@... Date: 2014-12-31T20:43:55+00:00 Subject: [ruby-core:67259] [ruby-trunk - Bug #10684] Block arity changes through Enumerable methods Issue #10684 has been updated by Jake Sower. Blocks traveling through methods in Enumerable have their arity changed before reaching #each. Example: ```ruby class MyEnumerable include Enumerable def initialize(ary) @ary = ary end def each(&block) puts block.arity @ary.each(&block) end end my_enum = MyEnumerable.new([1,2,3]) my_enum.each{|x| x} # outputs 1 my_enum.detect{|x| x} # outputs -1 ``` This is surprising behavior. I would expect the output to be 1 in both cases since the blocks appear identical to me as a programmer. ---------------------------------------- Bug #10684: Block arity changes through Enumerable methods https://bugs.ruby-lang.org/issues/10684#change-50726 * Author: Jake Sower * Status: Open * Priority: Normal * Assignee: * Category: * Target version: * ruby -v: 2.2.0 * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- Blocks traveling through methods in Enumerable have their arity changed before reaching #each. Example: class MyEnumerator include Enumerable def initialize(ary) @ary = ary end def each(&block) puts block.arity @ary.each(&block) end end my_enum = MyEnumerator.new([1,2,3]) my_enum.each{|x| x} # outputs 1 my_enum.detect{|x| x} # outputs -1 This is surprising behavior. I would expect the output to be 1 in both cases since the blocks appear identical to me as a programmer. -- https://bugs.ruby-lang.org/