Method: RUIC#assert
- Defined in:
- lib/ruic.rb
#assert(condition = :CONDITIONNOTSUPPLIED, msg = nil, &block) ⇒ Object
Simple assertion mechanism to be used within scripts.
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ruic.rb', line 135 def assert(condition=:CONDITIONNOTSUPPLIED,msg=nil,&block) if block && condition==:CONDITIONNOTSUPPLIED msg = yield condition = msg.is_a?(String) ? eval(msg,block.binding) : msg end condition || begin file, line, _ = caller.first.split(':') puts "#{"#{msg} : " unless msg.nil?}assertion failed (#{file} line #{line})" exit 1 end end |