Class: SyntaxTree::Else

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Else represents the end of an if, unless, or case chain.

if variable
else
end

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(keyword:, statements:, location:, comments: []) ⇒ Else



4164
4165
4166
4167
4168
4169
# File 'lib/syntax_tree/node.rb', line 4164

def initialize(keyword:, statements:, location:, comments: [])
  @keyword = keyword
  @statements = statements
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



4162
4163
4164
# File 'lib/syntax_tree/node.rb', line 4162

def comments
  @comments
end

#keywordObject (readonly)

Kw

the else keyword



4156
4157
4158
# File 'lib/syntax_tree/node.rb', line 4156

def keyword
  @keyword
end

#statementsObject (readonly)

Statements

the expressions to be executed



4159
4160
4161
# File 'lib/syntax_tree/node.rb', line 4159

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



4171
4172
4173
# File 'lib/syntax_tree/node.rb', line 4171

def accept(visitor)
  visitor.visit_else(self)
end

#child_nodesObject Also known as: deconstruct



4175
4176
4177
# File 'lib/syntax_tree/node.rb', line 4175

def child_nodes
  [keyword, statements]
end

#deconstruct_keys(_keys) ⇒ Object



4181
4182
4183
4184
4185
4186
4187
4188
# File 'lib/syntax_tree/node.rb', line 4181

def deconstruct_keys(_keys)
  {
    keyword: keyword,
    statements: statements,
    location: location,
    comments: comments
  }
end

#format(q) ⇒ Object



4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
# File 'lib/syntax_tree/node.rb', line 4190

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