No commit activity in last 3 years
No release in over 3 years
Raises exceptions or runtime warnings when calling methods whose arguments default to global variables.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.0
 Project Readme

stricter_global_usage¶ ↑

<img src=“https://secure.travis-ci.org/mark-rushakoff/StricterGlobalUsage.png?branch=master” />

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 © 2012 Mark Rushakoff

Available under the terms of the MIT license.