Class: Yadriggy::Conditional
- Includes:
- AstHelper
- Defined in:
- lib/yadriggy/ast.rb
Overview
if, unless, modifier if/unless, and ternary if (?:).
Instance Attribute Summary collapse
-
#all_elsif ⇒ Array<ASTnode>
readonly
Returns the elsif-expressions.
-
#cond ⇒ ASTnode
readonly
The condition expression.
-
#else ⇒ ASTnode|nil
readonly
The else-expression.
-
#op ⇒ Symbol
readonly
:if,:unless,:if_mod,:unless_mod, or:ifop. -
#then ⇒ ASTnode
readonly
The then-expressin.
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
-
#initialize(sexp) ⇒ Conditional
constructor
A new instance of Conditional.
Methods included from AstHelper
#has_tag?, #to_node, #to_nodes
Methods inherited from ASTnode
#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class
Constructor Details
#initialize(sexp) ⇒ Conditional
Returns a new instance of Conditional.
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 |
# File 'lib/yadriggy/ast.rb', line 1067 def initialize(sexp) @op = sexp[0] @cond = to_node(sexp[1]) @all_elsif = [] case @op when :ifop # ternary if @then = to_node(sexp[2]) @else = to_node(sexp[3]) when :if_mod, :unless_mod # modifier if/unless @then = to_node(sexp[2]) @else = nil else # if/unless @then = Exprs.make(sexp[2]) initialize_else(sexp[3]) end add_child(@cond) add_child(@then) add_child(@else) @all_elsif.each do |pair| pair.each { |e| add_child(e) } end end |
Instance Attribute Details
#all_elsif ⇒ Array<ASTnode> (readonly)
Returns the elsif-expressions.
1060 1061 1062 |
# File 'lib/yadriggy/ast.rb', line 1060 def all_elsif @all_elsif end |
#cond ⇒ ASTnode (readonly)
Returns the condition expression.
1052 1053 1054 |
# File 'lib/yadriggy/ast.rb', line 1052 def cond @cond end |
#else ⇒ ASTnode|nil (readonly)
Returns the else-expression.
1063 1064 1065 |
# File 'lib/yadriggy/ast.rb', line 1063 def else @else end |
#op ⇒ Symbol (readonly)
Returns :if, :unless, :if_mod, :unless_mod,
or :ifop.
1049 1050 1051 |
# File 'lib/yadriggy/ast.rb', line 1049 def op @op end |
#then ⇒ ASTnode (readonly)
Returns the then-expressin.
1055 1056 1057 |
# File 'lib/yadriggy/ast.rb', line 1055 def then @then end |
Class Method Details
.tags ⇒ Object
1065 |
# File 'lib/yadriggy/ast.rb', line 1065 def self.() [:if, :unless, :ifop, :if_mod, :unless_mod] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
1093 1094 1095 |
# File 'lib/yadriggy/ast.rb', line 1093 def accept(evaluator) evaluator.conditional(self) end |