Project

General

Profile

Actions

Bug #13336

closed

Default Parameters don't work

Added by herbert.bonaffini@gmail.com (Herbert Bonaffini) over 7 years ago. Updated about 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:80252]

Description

def funny(a = true, b: nil)
  p a
end

funny([1,2,3]) # => [1,2,3]

funny({k:1}) # => in `funny': unknown keyword: k (ArgumentError)

Files

hello_bug.rb (132 Bytes) hello_bug.rb herbert.bonaffini@gmail.com (Herbert Bonaffini), 03/20/2017 05:31 PM

Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #14183: "Real" keyword argumentClosedActions
Is duplicate of Ruby master - Bug #12717: Optional argument treated as kwargClosedmatz (Yukihiro Matsumoto)Actions
Actions #1

Updated by ko1 (Koichi Sasada) over 7 years ago

  • Description updated (diff)

Updated by ko1 (Koichi Sasada) over 7 years ago

  • Assignee set to mame (Yusuke Endoh)

mame-san: what do you think about it?

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Description updated (diff)
  • Assignee deleted (mame (Yusuke Endoh))

Updated by mame (Yusuke Endoh) over 7 years ago

This is intended. If a method accepts keyword arguments and if its last argument is a hash object, it is considered for keyword arguments. If you want to pass a hash as the first parameter, you need to explicitly pass a hash for keyword arguments, i.e., funny({k: 1}, {}).

Actions #5

Updated by hsbt (Hiroshi SHIBATA) almost 7 years ago

Updated by marcandre (Marc-Andre Lafortune) about 6 years ago

  • Status changed from Open to Closed

This is a duplicate of #12717, so closing this.

Actions #7

Updated by marcandre (Marc-Andre Lafortune) about 6 years ago

  • Is duplicate of Bug #12717: Optional argument treated as kwarg added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0