Project

General

Profile

Actions

Bug #12104

closed

Procs keyword arguments affect value of previous argument

Added by cheerfulstoic (Brian Underwood) about 8 years ago. Updated about 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
Tested in 2.3.0 and 2.2.3
[ruby-core:73949]

Description

This seems like a bug to me:

2.3.0 :001 > p = Proc.new {|nodes, match_array: false| puts nodes.inspect }
 => #<Proc:0x007fa52c0659e0@(irb):1>
2.3.0 :002 > p.call([])
nil
 => nil
2.3.0 :003 >  p.call([], match_array: true)
[]
 => nil

When I try the same thing in a method I get the behavior I would expect:

2.3.0 :004 > def foo(nodes, match_array: false)
2.3.0 :005?>   puts nodes.inspect
2.3.0 :006?>   end
 => :foo
2.3.0 :007 > foo([])
[]
 => nil
2.3.0 :008 > foo([], match_array: true)
[]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0