Project

General

Profile

Actions

Bug #13391

closed

wrong number of arguments error for Hash#map when lambda given

Added by tomog105 (Tomohiro Ogoke) almost 5 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
[ruby-dev:50063]

Description

内容

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"

Related issues

Related to Ruby master - Bug #12705: yielding args to a lambda uses block/proc rather than lambda/method semanticsClosednobu (Nobuyoshi Nakada)Actions
Has duplicate Ruby master - Bug #13404: Hash#any? yields arguments to lambdas with proc semanticsRejectedActions
Actions

Also available in: Atom PDF