Created
December 2, 2010 21:12
-
-
Save czarneckid/726069 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Define a constant if not defined: | |
define_if_not_defined(:A, 1) | |
assert_equal 1, A | |
Define a constant and redefine it: | |
define_if_not_defined(:B, 1) | |
redefine_without_warning(:B, 2) | |
assert_equal 2, B | |
Redefine a constant which should set the constant: | |
redefine_without_warning(:C, 3) | |
assert_equal 3, C | |
Define a constant within a module: | |
Math.define_if_not_defined(:FOO, 2 * Math::PI) | |
assert_equal 2 * Math::PI, Math::FOO | |
Define and redefine a constant within a module: | |
Math.define_if_not_defined(:BAR, 3) | |
Math.redefine_without_warning(:BAR, 5) | |
assert_equal 5, Math::BAR | |
Redefine a constant within a module which should set the constant: | |
Math.redefine_without_warning(:AMAZING, 3) | |
assert_equal 3, Math::AMAZING |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment