Actions
Bug #12104
closedProcs keyword arguments affect value of previous argument
Bug #12104:
Procs keyword arguments affect value of previous argument
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:
Updated by cheerfulstoic (Brian Underwood) over 10 years ago
Updated by cheerfulstoic (Brian Underwood) over 10 years ago
Looking deeper now it seems to be that this is because the first argument is an Array and that when that happens it's interpreting that as the elements of the array being the arguments of the Proc. Is that supposed to happen?
Updated by ko1 (Koichi Sasada) over 10 years ago
- Status changed from Open to Rejected
You are right.
It is intentional.
Updated by znz (Kazuhiro NISHIYAMA) over 10 years ago
How about using lambda instead of Proc.new?
Updated by hsbt (Hiroshi SHIBATA) over 8 years ago
- Related to Feature #14183: "Real" keyword argument added
Updated by marcandre (Marc-Andre Lafortune) almost 8 years ago
- Related to deleted (Feature #14183: "Real" keyword argument)
Actions