Project

General

Profile

Actions

Feature #21675

open

Advent of Pattern Matching

Feature #21675: Advent of Pattern Matching

Added by baweaver (Brandon Weaver) 1 day ago. Updated about 3 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:123737]

Description

Ruby pattern matching is a very useful feature, but many of the core classes to not leverage it currently. Given this I would like to directly invest in opening PRs to add this functionality and see how many cases we can reasonably add as we approach Ruby 4.0.

I have already started here:

But what I am currently considering looking at first are:

  • Pathname - Path manipulation is ubiquitous. Pattern matching on path components (dirname, basename, extname)
    would simplify file handling logic.
  • URI::Generic - URL routing and parsing would benefit from matching on scheme, host, port, and path components.
  • IPAddr - Network programming would benefit from matching on IP address components and families for filtering
    and routing logic.
  • File::Stat - File metadata inspection is common. Matching on size, mode, timestamps, and file type predicates
    would simplify permission and type checks.
  • Process::Status - Process exit status checking is verbose. Matching on exitstatus, signals, and success state
    would clarify intent.
  • Addrinfo - Socket programming would benefit from matching on address family, socket type, and IP address/port
    for connection handling.
  • OpenSSL::X509::Certificate - Certificate validation logic could be cleaner with matching on subject, issuer,
    and validity dates.
  • OpenSSL::X509::Name - Distinguished name parsing for certificate handling would benefit from component
    extraction.
  • Gem::Requirement - Complements Gem::Version for dependency management patterns.
  • Gem::Specification - Gem metadata inspection in tooling could benefit from structured matching.

If this is of interest I will start looking for more areas as well. My goal is to make this a feature that is well supported throughout common libraries in Ruby.

We can use this issue as a potential staging ground for discussion of what else might make sense.

Actions

Also available in: PDF Atom