Skip to content

🐛 RubyGem version silently does nothing due to __FILE__ == $0 check #92

@gwintrob

Description

@gwintrob

Description

When installing via gem install try-cli, the try command produces no output and silently exits. This affects version 1.7.1 (and likely earlier versions).

Root Cause

In bin/try:

require_relative '../try'

In try.rb, all main execution logic is guarded by:

if __FILE__ == $0

When bin/try uses require_relative, __FILE__ in try.rb is the path to try.rb, but $0 remains the path to bin/try. They never match, so the main code block is skipped entirely.

Fix

Change bin/try to set $0 before loading:

#!/usr/bin/env ruby
# frozen_string_literal: true

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

To reproduce

gem install try-cli
try          # No output, exits silently
try --help   # No output, exits silently

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions