aarontc aarontc - 3 months ago 20
Ruby Question

RubyMine: Unresolved Ruby Reference for global variable

Running RubyMine 2016.2.4. This project has a "global" singleton called

. All over the codebase this file is
'd to get access to runtime dependencies. RubyMine is showing "Unresolved Ruby Reference" for every instance of
in classes which use this global.

Mock-up of how the
file looks:

require 'singleton'

class Environment
include Singleton
def log

$environment ||= Environment.instance

Example usage which RubyMine complains about:

require_relative '../environment'

class FancyWorker
def run
$environment.log.info 'Running!'

I've tried searching to no avail on how to resolve this inspection problem in RubyMine. I don't want to disable the inspection since it is useful for finding legitimate problems - but this is not a legitimate issue.

(Please keep commentary about globals being bad to yourself, I didn't make that design decision - I just want to help RubyMine understand the reference.)


I think you found a bug on RubyMine. Try changing:

$environment ||= Environment.instance


$environment = $environment || Environment.instance

or just assign it if you're sure you won't be defining $environment anywhere else.