Project

General

Profile

Actions

Bug #10684

closed

Block arity changes through Enumerable methods

Added by jakesower (Jake Sower) over 9 years ago. Updated over 3 years ago.

Status:
Rejected
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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0