Class: SyntaxTree::Elsif
Overview
Elsif represents another clause in an if or unless chain.
if variable
elsif other_variable
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#consequent ⇒ Object
readonly
- nil | Elsif | Else
-
the next clause in the chain.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ Elsif
constructor
A new instance of Elsif.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ Elsif
Returns a new instance of Elsif.
4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 |
# File 'lib/syntax_tree/node.rb', line 4086 def initialize( predicate:, statements:, consequent:, location:, comments: [] ) @predicate = predicate @statements = statements @consequent = consequent @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4084 4085 4086 |
# File 'lib/syntax_tree/node.rb', line 4084 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil | Elsif | Else
-
the next clause in the chain
4081 4082 4083 |
# File 'lib/syntax_tree/node.rb', line 4081 def consequent @consequent end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
4075 4076 4077 |
# File 'lib/syntax_tree/node.rb', line 4075 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
4078 4079 4080 |
# File 'lib/syntax_tree/node.rb', line 4078 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
4100 4101 4102 |
# File 'lib/syntax_tree/node.rb', line 4100 def accept(visitor) visitor.visit_elsif(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4104 4105 4106 |
# File 'lib/syntax_tree/node.rb', line 4104 def child_nodes [predicate, statements, consequent] end |
#deconstruct_keys(_keys) ⇒ Object
4110 4111 4112 4113 4114 4115 4116 4117 4118 |
# File 'lib/syntax_tree/node.rb', line 4110 def deconstruct_keys(_keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 |
# File 'lib/syntax_tree/node.rb', line 4120 def format(q) q.group do q.group do q.text("elsif ") q.nest("elsif".length - 1) { q.format(predicate) } end unless statements.empty? q.indent do q.breakable(force: true) q.format(statements) end end if consequent q.group do q.breakable(force: true) q.format(consequent) end end end end |