Skip to content

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

Merged
evanphx merged 2 commits into
evanphx:masterfrom
paddor:fix-ruby4-benchmark-warning
May 21, 2026
Merged

Fix Ruby 4.0 warning: use require_relative for internal files#148
evanphx merged 2 commits into
evanphx:masterfrom
paddor:fix-ruby4-benchmark-warning

Conversation

@paddor

@paddor paddor commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

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

eregon commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Which warnings?

@eregon

eregon commented Mar 11, 2026

Copy link
Copy Markdown
Contributor
$ 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.

Comment thread test/test_benchmark_ips.rb Outdated
@paddor

paddor commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

Updated

@eregon eregon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@evanphx
evanphx merged commit 55bdcd1 into evanphx:master May 21, 2026
13 checks passed
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.

3 participants