Class: GraphMatching::Assertion
- Inherits:
-
Object
- Object
- GraphMatching::Assertion
- Defined in:
- lib/graph_matching/assertion.rb
Overview
Provides expressive methods for common runtime assertions, e.g.
assert(banana).is_a(Fruit)
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
Instance Method Summary collapse
- #eq(other) ⇒ Object
- #gte(other) ⇒ Object
-
#initialize(obj) ⇒ Assertion
constructor
A new instance of Assertion.
-
#is_a(klass) ⇒ Object
rubocop:disable Naming/PredicateName.
-
#not_nil ⇒ Object
rubocop:enable Naming/PredicateName.
Constructor Details
#initialize(obj) ⇒ Assertion
Returns a new instance of Assertion.
11 12 13 |
# File 'lib/graph_matching/assertion.rb', line 11 def initialize(obj) @obj = obj end |
Instance Attribute Details
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
9 10 11 |
# File 'lib/graph_matching/assertion.rb', line 9 def obj @obj end |
Instance Method Details
#eq(other) ⇒ Object
15 16 17 18 19 |
# File 'lib/graph_matching/assertion.rb', line 15 def eq(other) unless obj == other raise "Expected #{other}, got #{obj}" end end |
#gte(other) ⇒ Object
21 22 23 24 25 |
# 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) ⇒ Object
rubocop:disable Naming/PredicateName
28 29 30 31 32 |
# 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 ⇒ Object
rubocop:enable Naming/PredicateName
35 36 37 38 39 |
# File 'lib/graph_matching/assertion.rb', line 35 def not_nil if obj.nil? raise 'Unexpected nil' end end |