From: "baweaver (Brandon Weaver) via ruby-core" Date: 2025-11-09T03:40:23+00:00 Subject: [ruby-core:123739] [Ruby Feature#21675] Advent of Pattern Matching Issue #21675 has been updated by baweaver (Brandon Weaver). ### Net::HTTP I think this provides good coverage so far, but might look into others later: * [Add pattern matching support to Net::HTTPGenericRequest](https://github.com/ruby/net-http/pull/241) * [Add pattern matching support to Net::HTTPResponse](https://github.com/ruby/net-http/pull/240) * [Add pattern matching support to Net::HTTP](https://github.com/ruby/net-http/pull/242) * [Add pattern matching support to Net::HTTPExceptions](https://github.com/ruby/net-http/pull/243) ### RubyGems Just starting in on some of these, though the `Gem::Version` was what kicked this off initially in a side-bar conversation. * [Add pattern matching support to Gem::Version](https://github.com/ruby/rubygems/pull/9060) * [Add pattern matching support to Gem::Platform](https://github.com/ruby/rubygems/pull/9062) * [Add pattern matching support to Gem::Dependency](https://github.com/ruby/rubygems/pull/9063) * [Add pattern matching support to Gem::NameTuple](https://github.com/ruby/rubygems/pull/9064) ---------------------------------------- Feature #21675: Advent of Pattern Matching https://bugs.ruby-lang.org/issues/21675#change-115129 * Author: baweaver (Brandon Weaver) * Status: Open ---------------------------------------- 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: * `Gem::Version` - https://github.com/ruby/ruby/pull/15109 * `Net::HTTPResponse` - https://github.com/ruby/ruby/pull/15110 * `Net::HTTPGenericRequest` - https://github.com/ruby/ruby/pull/15111 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. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/