Class: Steep::Subtyping::Result::Any
- Defined in:
- lib/steep/subtyping/result.rb
Instance Attribute Summary collapse
-
#branches ⇒ Object
readonly
Returns the value of attribute branches.
Attributes inherited from Base
Instance Method Summary collapse
-
#add(*relations, &block) ⇒ Object
Returns ‘false` if no future `#add` changes the result.
- #failure_path(path = []) ⇒ Object
-
#initialize(relation) ⇒ Any
constructor
A new instance of Any.
- #success? ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(relation) ⇒ Any
Returns a new instance of Any.
129 130 131 132 133 |
# File 'lib/steep/subtyping/result.rb', line 129 def initialize(relation) super relation @branches = [] @success = false end |
Instance Attribute Details
#branches ⇒ Object (readonly)
Returns the value of attribute branches.
127 128 129 |
# File 'lib/steep/subtyping/result.rb', line 127 def branches @branches end |
Instance Method Details
#add(*relations, &block) ⇒ Object
Returns ‘false` if no future `#add` changes the result.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/steep/subtyping/result.rb', line 136 def add(*relations, &block) relations.each do |relation| if failure? result = yield(relation) branches << result else # Already succeeded. branches << Skip.new(relation) end end # No need to test more branches if already succeeded. failure? end |
#failure_path(path = []) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/steep/subtyping/result.rb', line 155 def failure_path(path = []) if failure? path.unshift(self) if r = branches.find(&:failure?) r.failure_path(path) else path end end end |
#success? ⇒ Boolean
151 152 153 |
# File 'lib/steep/subtyping/result.rb', line 151 def success? @success ||= branches.any?(&:success?) end |