Issue #13391 has been updated by hsbt (Hiroshi SHIBATA).

Status changed from Open to Assigned
Assignee set to ko1 (Koichi Sasada)

>ko1

Please review https://github.com/ruby/ruby/compare/trunk...nobu:bug/13391-map-arity



----------------------------------------
Bug #13391: wrong number of arguments error for Hash#map when lambda given
https://bugs.ruby-lang.org/issues/13391#change-65785

* Author: tomog105 (Tomohiro Ogoke)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
## 内容

Ruby 2.4.1 にて `Hash` オブジェクトの `#map` に 2つの引数を受け取る lambda を渡した際、
arguments error が発生します。

Ruby 2.4.0, ないし 2.3.4 では同じコードを実行した際にはエラーは発生していませんでしたが、
trunk でも同じエラーが発生します。

## 再現コード

~~~
% cat lambda.rb
hash = { a: 'hoge', b: 'fuga' }
lambda = -> (k, v) { p "#{k}:#{v}" }
hash.map(&lambda)
~~~

## 実行結果

~~~
% ruby -v lambda.rb
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
lambda.rb:2:in `block in <main>': wrong number of arguments (given 1, expected 2) (ArgumentError)
	from lambda.rb:3:in `each'
	from lambda.rb:3:in `map'
	from lambda.rb:3:in `<main>'

% RBENV_VERSION=2.5.0-dev ruby -v lambda.rb
ruby 2.5.0dev (2017-03-31 trunk 58224) [x86_64-darwin15]
	from lambda.rb:3:in `<main>'
	from lambda.rb:3:in `map'
	from lambda.rb:3:in `each'
lambda.rb:2:in `block in <main>': wrong number of arguments (given 1, expected 2) (ArgumentError)

% RBENV_VERSION=2.4.0 ruby -v lambda.rb
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin15]
"a:hoge"
"b:fuga"

% RBENV_VERSION=2.3.4 ruby -v lambda.rb
ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-darwin15]
"a:hoge"
"b:fuga"
~~~

また、 `#map` ではなく `#each` を使う場合には、同じ lambda ブロックを渡した際でもエラーにはなりません。

~~~
% cat lambda_each.rb
hash = { a: 'hoge', b: 'fuga' }
lambda = -> (k, v) { p "#{k}:#{v}" }
hash.each(&lambda)

% ruby -v lambda_each.rb
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
"a:hoge"
"b:fuga"

% RBENV_VERSION=2.5.0-dev ruby -v lambda_each.rb
ruby 2.5.0dev (2017-03-31 trunk 58224) [x86_64-darwin15]
"a:hoge"
"b:fuga"
~~~



-- 
https://bugs.ruby-lang.org/