No description or website provided.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
.travis.yml
ChangeLog.rdoc
Gemfile
LICENSE.txt
README.rdoc
Rakefile
stricter_global_usage.gemspec

README.rdoc

stricter_global_usage

Description

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.

Features

Currently, StricterGlobalUsage wraps Array#join and String#split, applying the specified strategy if one of those methods is called without explicit arguments.

Examples

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

Requirements

StricterGlobalUsage does not depend on any other gems.

Install

$ gem install stricter_global_usage

Copyright

Copyright © 2012 Mark Rushakoff

Available under the terms of the MIT license.