Skip to content

Fix Ruby 4.0 warning: use require_relative for internal files#148

Open
paddor wants to merge 2 commits intoevanphx:masterfrom
paddor:fix-ruby4-benchmark-warning
Open

Fix Ruby 4.0 warning: use require_relative for internal files#148
paddor wants to merge 2 commits intoevanphx:masterfrom
paddor:fix-ruby4-benchmark-warning

Conversation

@paddor
Copy link
Copy Markdown

@paddor paddor commented Mar 10, 2026

Replace all require calls for internal files with require_relative in lib/benchmark/ips.rb and the test suite to fix warnings on Ruby 4.0.

Ruby 4.0 removed `benchmark` from default gems. When benchmark-ips
uses `require 'benchmark/timing'`, Ruby's gem activation system
sees the `benchmark/` prefix and warns that the `benchmark` gem is
not a default gem, even though all these files belong to
benchmark-ips.

Using `require_relative` bypasses gem activation entirely, resolving
the warning:

  benchmark/timing is found in benchmark, which is not part of the
  default gems since Ruby 4.0.0.
@eregon
Copy link
Copy Markdown
Contributor

eregon commented Mar 11, 2026

Which warnings?

@eregon
Copy link
Copy Markdown
Contributor

eregon commented Mar 11, 2026

$ bundle exec rake
/home/eregon/code/benchmark-ips/test/test_benchmark_ips.rb:2: warning: benchmark/ips is found in benchmark, which is not part of the default gems since Ruby 4.0.0.

That seems a clear bug of https://github.com/ruby/ruby/blob/master/lib/bundled_gems.rb.
It's filed as https://bugs.ruby-lang.org/issues/21828, I'll reopen.

@paddor
Copy link
Copy Markdown
Author

paddor commented Mar 12, 2026

Updated

Copy link
Copy Markdown
Contributor

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

2 participants