Class: SyntaxTree::Else
Overview
Else represents the end of an if
, unless
, or case
chain.
if variable
else
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#keyword ⇒ Object
readonly
- Kw
-
the else keyword.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(keyword: nil, statements: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(keyword:, statements:, location:) ⇒ Else
constructor
A new instance of Else.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(keyword:, statements:, location:) ⇒ Else
Returns a new instance of Else.
4799 4800 4801 4802 4803 4804 |
# File 'lib/syntax_tree/node.rb', line 4799 def initialize(keyword:, statements:, location:) @keyword = keyword @statements = statements @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4797 4798 4799 |
# File 'lib/syntax_tree/node.rb', line 4797 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the else keyword
4791 4792 4793 |
# File 'lib/syntax_tree/node.rb', line 4791 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
4794 4795 4796 |
# File 'lib/syntax_tree/node.rb', line 4794 def statements @statements end |
Instance Method Details
#===(other) ⇒ Object
4850 4851 4852 4853 |
# File 'lib/syntax_tree/node.rb', line 4850 def ===(other) other.is_a?(Else) && keyword === other.keyword && statements === other.statements end |
#accept(visitor) ⇒ Object
4806 4807 4808 |
# File 'lib/syntax_tree/node.rb', line 4806 def accept(visitor) visitor.visit_else(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4810 4811 4812 |
# File 'lib/syntax_tree/node.rb', line 4810 def child_nodes [keyword, statements] end |
#copy(keyword: nil, statements: nil, location: nil) ⇒ Object
4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 |
# File 'lib/syntax_tree/node.rb', line 4814 def copy(keyword: nil, statements: nil, location: nil) node = Else.new( keyword: keyword || self.keyword, statements: statements || self.statements, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
4828 4829 4830 4831 4832 4833 4834 4835 |
# File 'lib/syntax_tree/node.rb', line 4828 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 |
# File 'lib/syntax_tree/node.rb', line 4837 def format(q) q.group do q.format(keyword) unless statements.empty? q.indent do q.breakable_force q.format(statements) end end end end |