rake icon indicating copy to clipboard operation
rake copied to clipboard

Fix TaskArguments#deconstruct_keys with keys = nil

Open nevans opened this issue 7 months ago • 0 comments

This fixes a bug in the initial implementation (#515):

#deconstruct_keys should handle keys == nil, or **rest will be broken.

For example, the normal behavior looks like this:

  {a: 1, b: 2, c: 3} => {a:, **rest}
  a     # => 1
  rest  # => {b: 2, c: 3}

But without handling keys == nil, we'll get this:

  class Example
    def initialize(hash) = @hash = hash
    def deconstruct_keys(keys) = @hash.slice(*keys)
  end

  Example.new({a: 1, b: 2, c: 3}) => {a:, **rest}
  # !> "#{inspect}: key not found: :a" (NoMatchingPatternKeyError)

nevans avatar Jun 02 '25 15:06 nevans