Project

General

Profile

Actions

Bug #14909

closed

Method call with object that has to_hash method crashes (method with splat and keyword arguments)

Added by johannes_luedke (Johannes Lüdke) almost 6 years ago. Updated about 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin17]
[ruby-core:87922]

Description

In a method with a splat method argument followed by a keyword argument, it leads to an ArgumentError when calling the method with an object that reacts to to_hash

def my_func(*objects, error_code: 400)
  objects.inspect
end

class Test
  def to_hash
    # an example hash
    { to_hash_key: "to_hash" }
  end
end

my_func(Test.new)

Observed result: an exception is raised: in my_func: unknown keyword: to_hash_key (ArgumentError)
Expected result: [#<Test:0x007fc8c9825318>] is returned by the my_func call

It should behave the same when calling with objects that have a to_hash method and objects that don't, shouldn't it?


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #14930: sample/trick2018Closedmame (Yusuke Endoh)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0