Skip to content

Conversation

@ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Nov 2, 2025

Use require_relative instead of $LOAD_PATH in gemspec

Description

This PR simplifies the gemspec by replacing the $LOAD_PATH manipulation with require_relative, which is more idiomatic and cleaner for Ruby gems.

Changes

  • Removed $LOAD_PATH.unshift File.expand_path('lib', __dir__)
  • Replaced require 'grape/version' with require_relative 'lib/grape/version'

Benefits

  1. Simplicity: require_relative is more straightforward and doesn't mutate global state
  2. Idiomatic: Follows modern Ruby best practices for gemspecs
  3. Safety: Avoids potential pollution of $LOAD_PATH that could affect other gems

Context

This follows a modern Ruby convention where require_relative is preferred over manipulating $LOAD_PATH in gemspecs. The previous approach was added in #1758 to fix issues with Grape::VERSION potentially referencing system-wide installed gem versions, but require_relative provides the same isolation without global state mutation.

Testing

  • ✅ All existing tests pass
  • ✅ Gem builds successfully
  • ✅ Version constant loads correctly
@grape-bot
Copy link

1 Message
📖 We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!

Generated by 🚫 Danger

@ericproulx ericproulx force-pushed the use_require_relative_in_gemspec branch from 8f2783f to cbfe67c Compare November 2, 2025 13:06
@dblock dblock merged commit e159a1e into master Nov 2, 2025
103 checks passed
@dblock dblock deleted the use_require_relative_in_gemspec branch November 2, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants