Skip to content

Conversation

@baweaver
Copy link
Contributor

@baweaver baweaver commented Nov 9, 2025

This PR adds deconstruct_keys to Net::HTTP, enabling pattern matching on HTTP client configuration and state.

Usage

case http_client
in address: 'localhost', port: 3000, use_ssl?: false
  'local development'
in use_ssl?: true, port: 443
  'secure production'
in started?: true
  'active connection'
end

Implementation

  • Added PATTERN_MATCHING_KEYS constant defining valid keys: address, port, use_ssl?, started?, read_timeout, write_timeout, open_timeout
  • Implemented deconstruct_keys following Ruby pattern matching best practices
  • Returns only requested keys when specified, all valid keys when keys is nil
  • Tests wrapped in instance_eval with SyntaxError rescue for Ruby 2.6 compatibility

Implements deconstruct_keys to enable pattern matching on HTTP client
configuration and state.

Example:
  case http_client
  in address: 'localhost', port: 3000, use_ssl?: false
    'local development'
  in use_ssl?: true, port: 443
    'secure production'
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant