Class: SyntaxTree::Ensure

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

Overview

Ensure represents the use of the ensure keyword and its subsequent statements.

begin
ensure
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: []) ⇒ Ensure

Returns a new instance of Ensure.



4290
4291
4292
4293
4294
4295
# File 'lib/syntax_tree/node.rb', line 4290

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



4288
4289
4290
# File 'lib/syntax_tree/node.rb', line 4288

def comments
  @comments
end

#keywordObject (readonly)

Kw

the ensure keyword that began this node



4282
4283
4284
# File 'lib/syntax_tree/node.rb', line 4282

def keyword
  @keyword
end

#statementsObject (readonly)

Statements

the expressions to be executed



4285
4286
4287
# File 'lib/syntax_tree/node.rb', line 4285

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



4297
4298
4299
# File 'lib/syntax_tree/node.rb', line 4297

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

#child_nodesObject Also known as: deconstruct



4301
4302
4303
# File 'lib/syntax_tree/node.rb', line 4301

def child_nodes
  [keyword, statements]
end

#deconstruct_keys(_keys) ⇒ Object



4307
4308
4309
4310
4311
4312
4313
4314
# File 'lib/syntax_tree/node.rb', line 4307

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

#format(q) ⇒ Object



4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
# File 'lib/syntax_tree/node.rb', line 4316

def format(q)
  q.format(keyword)

  unless statements.empty?
    q.indent do
      q.breakable(force: true)
      q.format(statements)
    end
  end
end