Class: Pione::Lang::CaseBranch
- Inherits:
-
ConditionalBranch
- Object
- StructX
- ConditionalBranch
- Pione::Lang::CaseBranch
- Defined in:
- lib/pione/lang/conditional-branch.rb
Overview
CaseBranch is a class for +case+ branches.
Instance Method Summary collapse
-
#eval(env) ⇒ Object
Return suitable context in the environment.
-
#validate(acceptances) ⇒ Object
Validate inner contexts based on the list of acceptances.
Methods included from Util::Positionable
#line_and_column, #pos, #set_source_position
Instance Method Details
#eval(env) ⇒ Object
Return suitable context in the environment.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pione/lang/conditional-branch.rb', line 59 def eval(env) # evaluate the condition val = expr.eval!(env) # return matched branch's context _, matched = when_contexts.find do |_expr, _context| val.call_pione_method(env, "==*", [_expr]).value end # return matched context, else-context, or empty context return matched || else_context || ConditionalBranchContext.new end |
#validate(acceptances) ⇒ Object
Validate inner contexts based on the list of acceptances.
53 54 55 56 |
# File 'lib/pione/lang/conditional-branch.rb', line 53 def validate(acceptances) when_contexts.each {|_expr, _context| _context.validate(acceptances)} else_context.validate(acceptances) end |