Guest User

Untitled

a guest
Jul 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. Define a constant if not defined:
  2.  
  3. define_if_not_defined(:A, 1)
  4.  
  5. assert_equal 1, A
  6.  
  7. Define a constant and redefine it:
  8.  
  9. define_if_not_defined(:B, 1)
  10. redefine_without_warning(:B, 2)
  11.  
  12. assert_equal 2, B
  13.  
  14. Redefine a constant which should set the constant:
  15.  
  16. redefine_without_warning(:C, 3)
  17.  
  18. assert_equal 3, C
  19.  
  20. Define a constant within a module:
  21.  
  22. Math.define_if_not_defined(:FOO, 2 * Math::PI)
  23.  
  24. assert_equal 2 * Math::PI, Math::FOO
  25.  
  26. Define and redefine a constant within a module:
  27.  
  28. Math.define_if_not_defined(:BAR, 3)
  29. Math.redefine_without_warning(:BAR, 5)
  30.  
  31. assert_equal 5, Math::BAR
  32.  
  33. Redefine a constant within a module which should set the constant:
  34.  
  35. Math.redefine_without_warning(:AMAZING, 3)
  36.  
  37. assert_equal 3, Math::AMAZING
Add Comment
Please, Sign In to add comment