class GraphMatching::Assertion
Provides expressive methods for common runtime assertions, e.g.
assert(banana).is_a(Fruit)
Attributes
obj[R]
Public Class Methods
new(obj)
click to toggle source
# File lib/graph_matching/assertion.rb, line 11 def initialize(obj) @obj = obj end
Public Instance Methods
eq(other)
click to toggle source
# File lib/graph_matching/assertion.rb, line 15 def eq(other) unless obj == other raise "Expected #{other}, got #{obj}" end end
gte(other)
click to toggle source
# File lib/graph_matching/assertion.rb, line 21 def gte(other) unless obj >= other raise "Expected #{obj} to be >= #{other}" end end
is_a(klass)
click to toggle source
rubocop:disable Naming/PredicateName
# File lib/graph_matching/assertion.rb, line 28 def is_a(klass) unless obj.is_a?(klass) raise TypeError, "Expected #{klass}, got #{obj.class}" end end
not_nil()
click to toggle source
rubocop:enable Naming/PredicateName
# File lib/graph_matching/assertion.rb, line 35 def not_nil if obj.nil? raise 'Unexpected nil' end end