Basic ruby assert function
1 2 def assert 3 raise "Assertion failed !" unless yield if $DEBUG 4 end
Usage :
1 2 def aFunc(i) 3 assert { i < 10 } 4 # ... 5 end 6 7 $DEBUG = true 8 # Ok. 9 aFunc(5) 10 # Raise Assert Exception. 11 aFunc(15) 12 13 $DEBUG = false 14 # Ok. 15 aFunc(5) 16 aFunc(15)