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, #pretty_print, #to_json
Constructor Details
#initialize(keyword:, statements:, location:) ⇒ Else
Returns a new instance of Else.
4720 4721 4722 4723 4724 4725 |
# File 'lib/syntax_tree/node.rb', line 4720 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
4718 4719 4720 |
# File 'lib/syntax_tree/node.rb', line 4718 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the else keyword
4712 4713 4714 |
# File 'lib/syntax_tree/node.rb', line 4712 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
4715 4716 4717 |
# File 'lib/syntax_tree/node.rb', line 4715 def statements @statements end |
Instance Method Details
#===(other) ⇒ Object
4771 4772 4773 4774 |
# File 'lib/syntax_tree/node.rb', line 4771 def ===(other) other.is_a?(Else) && keyword === other.keyword && statements === other.statements end |
#accept(visitor) ⇒ Object
4727 4728 4729 |
# File 'lib/syntax_tree/node.rb', line 4727 def accept(visitor) visitor.visit_else(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4731 4732 4733 |
# File 'lib/syntax_tree/node.rb', line 4731 def child_nodes [keyword, statements] end |
#copy(keyword: nil, statements: nil, location: nil) ⇒ Object
4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 |
# File 'lib/syntax_tree/node.rb', line 4735 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
4749 4750 4751 4752 4753 4754 4755 4756 |
# File 'lib/syntax_tree/node.rb', line 4749 def deconstruct_keys(_keys) { keyword: keyword, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 |
# File 'lib/syntax_tree/node.rb', line 4758 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 |