Skip to content

Conversation

@baweaver
Copy link
Contributor

@baweaver baweaver commented Nov 9, 2025

What was the end-user or developer problem that led to this PR?

Ruby 2.7+ introduced pattern matching, but Gem::Dependency does not support it. This makes dependency filtering and analysis more verbose than necessary, particularly when working with dependency trees or separating runtime from development dependencies.

The current approach requires multiple conditionals:

dependencies.each do |dep|
 if dep.type == :development
   skip_for_production
 elsif dep.type == :runtime
   check_version_compatibility(dep.requirement)
 end
end

What is your fix for the problem, implemented in this PR?

Added deconstruct_keys method to Gem::Dependency to enable pattern matching syntax.

Implementation:

  • deconstruct_keys returns a hash with keys :name, :type, :requirement, and :prerelease

This enables dependency-based pattern matching:

case dependency
in type: :development, name:
 skip_for_production
in type: :runtime, requirement:
 check_version_compatibility(requirement)
end

Or filtering dependencies:

dependencies.select { it in type: :runtime, prerelease: false }

Make sure the following tasks are checked

  • Describe the problem / feature
  • Write tests for features and bug fixes
  • Write code to solve the problem
  • Make sure you follow the current code style and write meaningful commit messages without tags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants