Module: Assertion

Included in:
Kwatable::Main, Kwatable::Manipulator
Defined in:
lib/kwatable/util/assertion.rb

Overview

utility module for assertion

ex.

require 'assertion'
include Assertion   # or extend Assertion
assert s && !s.empty?
assert! unless s && !s.empty?

Defined Under Namespace

Classes: AssertionError, UnreachableError

Class Method Summary collapse

Class Method Details

.assert(condition, message = '') ⇒ Object

raise AssertionError if condition is false

ex.

assert s && !s.empty?, "s=#{s.inspect}"


61
62
63
# File 'lib/kwatable/util/assertion.rb', line 61

def assert(condition, message='')
  _raise_error(AssertionError, message, caller()) unless condition
end

.assert!(message = '') ⇒ Object

raise AssertionError

ex.

assert! "s=#{s.inspect}" unless s && !s.empty?


72
73
74
# File 'lib/kwatable/util/assertion.rb', line 72

def assert! (message='')
  _raise_error(AssertionError, message, caller())
end

.unreachable(message = '') ⇒ Object

raise UnreachableError

ex.

case value
when true
  ...
when false
  ...
else
  unreachable
end


90
91
92
# File 'lib/kwatable/util/assertion.rb', line 90

def unreachable(message='')
  _raise_error(UnreachableError, message, caller())
end