Skip to content

Conversation

@achugr
Copy link

@achugr achugr commented Jan 17, 2026

Summary

Fix bin/try to properly set $0 when loading try.rb, ensuring gem installation works correctly

Problem

When installed as a gem, try.rb uses $0 to determine its own script path (line 996: script_path = File.expand_path($0)). The previous require_relative '../try' approach left $0 pointing to bin/try
instead of try.rb, breaking self-referential path logic.

Solution

Replace require_relative with explicit $0 assignment and load:

$0 = File.expand_path('../try.rb', __dir__)
load $0

This ensures try.rb sees the correct path in $0 whether run locally or via gem installation.

When installed via gem, require_relative doesn't trigger the
if __FILE__ == $0 guard in try.rb because $0 points to bin/try,
not try.rb.

Use load with $0 set to try.rb path so the guard evaluates to true.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@achugr
Copy link
Author

achugr commented Jan 19, 2026

@tobi gem install (recommended way as per the docs) does not work correctly, please take a look at the quick fix

@gwintrob
Copy link

This would fix #92!

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