Project

General

Profile

Bug #10684

Block arity changes through Enumerable methods

Added by jakesower (Jake Sower) almost 6 years ago. Updated 2 months ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:67258]

Description

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.

Also available in: Atom PDF