Project

General

Profile

Bug #13336

Default Parameters don't work

Added by herbert.bonaffini@gmail.com (Herbert Bonaffini) over 2 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
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

Related to Ruby master - Feature #14183: "Real" keyword argumentClosedActions
Is duplicate of Ruby master - Bug #12717: Optional argument treated as kwargClosedActions

History

#1

Updated by ko1 (Koichi Sasada) over 2 years ago

  • Description updated (diff)

Updated by ko1 (Koichi Sasada) over 2 years ago

  • Assignee set to mame (Yusuke Endoh)

mame-san: what do you think about it?

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

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

Updated by mame (Yusuke Endoh) over 2 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}, {}).

#5

Updated by hsbt (Hiroshi SHIBATA) almost 2 years ago

Updated by marcandre (Marc-Andre Lafortune) about 1 year ago

  • Status changed from Open to Closed

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

#7

Updated by marcandre (Marc-Andre Lafortune) about 1 year ago

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

Also available in: Atom PDF