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.
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 |
# File 'lib/yadriggy/ast.rb', line 1081 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.
1074 1075 1076 |
# File 'lib/yadriggy/ast.rb', line 1074 def all_elsif @all_elsif end |
#cond ⇒ ASTnode (readonly)
Returns the condition expression.
1066 1067 1068 |
# File 'lib/yadriggy/ast.rb', line 1066 def cond @cond end |
#else ⇒ ASTnode|nil (readonly)
Returns the else-expression.
1077 1078 1079 |
# File 'lib/yadriggy/ast.rb', line 1077 def else @else end |
#op ⇒ Symbol (readonly)
Returns :if
, :unless
, :if_mod
, :unless_mod
,
or :ifop
.
1063 1064 1065 |
# File 'lib/yadriggy/ast.rb', line 1063 def op @op end |
#then ⇒ ASTnode (readonly)
Returns the then-expressin.
1069 1070 1071 |
# File 'lib/yadriggy/ast.rb', line 1069 def then @then end |
Class Method Details
.tags ⇒ Object
1079 |
# File 'lib/yadriggy/ast.rb', line 1079 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.
1107 1108 1109 |
# File 'lib/yadriggy/ast.rb', line 1107 def accept(evaluator) evaluator.conditional(self) end |