Project

General

Profile

Actions

Bug #11039

closed

method_missing の *args 引数に symbol をキーにした hash だけを渡すと エラーとなる

Added by kiyono (yoshimitsu kiyono) about 9 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin13]
[ruby-dev:<unknown>]

Description

method_missing に 第3引数として キーワード引数を設定した上で、引数に symbol をキーにした Hash だけを渡すと
=> unknown keyword: a (ArgumentError)
となる。
※ 第3引数を付け足さなければエラーにならない。

引数が文字列をキーにした Hash であればエラーにならないため、キーが symbol でも Hash であるならば合わせた挙動であるべきではないでしょうか。


Files

foo.rb (244 Bytes) foo.rb 実行スクリプト kiyono (yoshimitsu kiyono), 04/07/2015 09:09 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #14183: "Real" keyword argumentClosedActions
Actions #1

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Open to Closed

With the acceptance of #14183, you now get a warning as the behavior will change in Ruby 3:

Foo.bar({ b: 1 })
# (irb):67: warning: The last argument is used as the keyword parameter
# (irb):58: warning: for `method_missing' defined here
# ArgumentError (unknown keyword: :b)

In Ruby 3, you will not get a warning, and the hash will be passed as a positional argument. To get the Ruby 3 behavior with the master branch:

Foo.bar({ b: 1 }, **(;{}))
# => [{:b=>1}]
Actions

Also available in: Atom PDF

Like0
Like0Like0