There are several methods in Ruby that use a default argument of a global variable; of those, Array#join and String#split are the main two that could potentially give you problems if someone sets the corresponding global variables to something other than the default. stricter_global_usage will raise an exception (default behavior) or give a runtime warning when you use a function and its argument falls back to the global variable - because chances are, that's not the behavior you intended.
Currently, StricterGlobalUsage wraps Array#join and String#split, applying the specified strategy if one of those methods is called without explicit arguments.
require 'stricter_global_usage' # default behavior: %w(cat dog).join # => raises exception! %w(cat dog).join($,) # => explictly uses default global variable # warn instead of raising exceptions ::StricterGlobalUsage::Strategy.use(:warn) 'one two'.split # => warns, but effectively the same as `'one two'.split($;)` # temporarily use a different strategy ::StricterGlobalUsage::Strategy.with(:silent) do 'one two'.split # => will not raise or warn end %w(cat dog).join # => will warn again
StricterGlobalUsage does not depend on any other gems.
$ gem install stricter_global_usage
Copyright © 2012 Mark Rushakoff
Available under the terms of the MIT license.