Skip to content

Instantly share code, notes, and snippets.

@czarneckid
Created December 2, 2010 21:12
Show Gist options
  • Save czarneckid/726069 to your computer and use it in GitHub Desktop.
Save czarneckid/726069 to your computer and use it in GitHub Desktop.
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