Skip to content

Fix a NoMethodError on Ruby 2.7 caused by Hash#except#468

Open
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:fix_hash_except_ruby_2_7
Open

Fix a NoMethodError on Ruby 2.7 caused by Hash#except#468
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:fix_hash_except_ruby_2_7

Conversation

@koic

@koic koic commented Jul 22, 2026

Copy link
Copy Markdown
Member

Motivation and Context

The gemspec already declares required_ruby_version >= 2.7.0, but the conformance Rake task used Hash#except to drop the :port option before handing the remaining options to Conformance::ClientRunner. Hash#except was only added in Ruby 3.0, so running rake conformance on Ruby 2.7 aborted before any scenario ran, raising NoMethodError: undefined method except for {}:Hash.

CI missed this because no job runs rake conformance on Ruby 2.7: the conformance workflow runs only on Ruby 4.0, while the Ruby 2.7.0 matrix entry runs rake test alone.

How Has This Been Tested?

Replace options.except(:port) with options.reject { |key, _| key == :port }, which has been available since well before Ruby 2.7 and returns an equivalent Hash without mutating the original. rake conformance now runs the full suite on Ruby 2.7, and its baseline still passes on current Ruby, verified on Ruby 4.0.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

## Motivation and Context

The gemspec already declares `required_ruby_version >= 2.7.0`, but the conformance Rake task used `Hash#except` to drop
the `:port` option before handing the remaining options to `Conformance::ClientRunner`. `Hash#except` was only added in Ruby 3.0,
so running `rake conformance` on Ruby 2.7 aborted before any scenario ran, raising `NoMethodError: undefined method except for {}:Hash`.

CI missed this because no job runs `rake conformance` on Ruby 2.7: the conformance workflow runs only on Ruby 4.0,
while the Ruby 2.7.0 matrix entry runs `rake test` alone.

## How Has This Been Tested?

Replace `options.except(:port)` with `options.reject { |key, _| key == :port }`, which has been available since well
before Ruby 2.7 and returns an equivalent Hash without mutating the original. `rake conformance` now runs the full suite on Ruby 2.7,
and its baseline still passes on current Ruby, verified on Ruby 4.0.

## Breaking Changes

None.
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