Project

General

Profile

Actions

Bug #10994

closed

Inconsistent behavior when mixing optional argument and keyword splat

Added by ruipserra (Rui Serra) almost 10 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin13]
[ruby-core:<unknown>]

Description

The following code produces inconsistent behavior:

def foo(x=nil, **kw) 
  x 
end

h = { "a" => 1 }

foo(h)                  # => {"a"=>1} 
foo(h).equal?(h)        # => false
foo(h, y: 1).equal?(h)  # => true

It seems that in this very specific case, foo is returning a copy of h instead of returning h itself. I guess this is an edge case in the keyword extraction process.

Thank you for your time.


Related issues 1 (0 open1 closed)

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

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Status changed from Open to Closed

With the acceptance of #14183, you now get:

foo(h) 
# => {"a"=>1}

foo(h).equal?(h)
# => true

foo(h, y: 1).equal?(h) 
# => true

Actions

Also available in: Atom PDF

Like0
Like0Like0