Project

General

Profile

Actions

Bug #7663

closed

Unable to invoke a method with `**kwargs` if the receiver doesn't define keyword arguments

Added by wycats (Yehuda Katz) almost 10 years ago. Updated almost 10 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
2.0.0dev
Backport:
[ruby-core:51270]

Description

This works:

def hello
puts "hello"
end

hello(*[])

This does not:

def hello
puts "hello"
end

hello(**{})

I may be misunderstanding the idea behind the keyword arguments, but I would expect them to behave similarly to regular arguments when used with splat.

Updated by matz (Yukihiro Matsumoto) almost 10 years ago

  • Status changed from Open to Rejected

Unlike regular argument, empty keyword argument is not equal to empty regular list.

Matz.

Updated by mame (Yusuke Endoh) almost 10 years ago

In the current design, keyword arguments are NOT omittable at a callee side.
In other words, you cannot pass keyword arguments to a method that does not support keyword argments.

Other possible behavior is to ignore the passed arguments silently (as you expected), but I'm afraid if it is rather error-prone than useful. It tends to hide bugs.

If you really want to do so, you can use ** parameter explicitly.

def hello(**dummy)
puts "hello"
end

A bare ** (#7662) is indeed useful in this use case. I'm not so positive to this use case itself, though.

Actions

Also available in: Atom PDF

Like0
Like0Like0