Project

General

Profile

Actions

Bug #10293

closed

splatting an empty hash in a method invocation sends an argument to the method (should send nothing)

Added by rits (First Last) about 10 years ago. Updated about 5 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]
[ruby-core:65263]

Description

irb(main):001:0> def foo; end; foo **{}
ArgumentError: wrong number of arguments (1 for 0)

note that splatting an empty array results in no arguments

this behavior is particularly problematic with send (dispatching to different methods)

send method_name, *possibly_empty_arg_list, **possibly_empty_keyarg_hash

one should not have to do

if possibly_empty_keyarg_hash.empty?
receiver.send method_name, *possibly_empty_arg_list
else
receiver.send method_name, *possibly_empty_arg_list, **possibly_empty_keyarg_hash
end

or

possibly_empty_arg_list << possibly_empty_keyarg_hash unless possibly_empty_keyarg_hash.empty?
receiver.send method_name, *possibly_empty_arg_list


Related issues 1 (0 open1 closed)

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0