Project

General

Profile

Actions

Bug #17595

closed

[Pattern Matching] deconstruct_keys with zero patterns supplies nil for keys argument

Added by baweaver (Brandon Weaver) about 3 years ago. Updated about 3 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:102315]

Description

Example:

Test = Struct.new(:a, :b) do
  def deconstruct_keys(ks)
    p ks: ks
    to_h.slice(*ks)
  end
end
# => Test

Test.new(1,2) in {}
# {:ks=>nil}
# => true

As users may call Array methods against the keys argument I consider this a potential bug that it returns nil for no supplied arguments.

Proposed Patch: Pass an empty array instead to maintain interface consistency.

Actions

Also available in: Atom PDF

Like0
Like0Like0