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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of Ensure.



4219
4220
4221
4222
4223
4224
# File 'lib/syntax_tree/node.rb', line 4219

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



4217
4218
4219
# File 'lib/syntax_tree/node.rb', line 4217

def comments
  @comments
end

#keywordObject (readonly)

Kw

the ensure keyword that began this node



4211
4212
4213
# File 'lib/syntax_tree/node.rb', line 4211

def keyword
  @keyword
end

#statementsObject (readonly)

Statements

the expressions to be executed



4214
4215
4216
# File 'lib/syntax_tree/node.rb', line 4214

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



4226
4227
4228
# File 'lib/syntax_tree/node.rb', line 4226

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

#child_nodesObject Also known as: deconstruct



4230
4231
4232
# File 'lib/syntax_tree/node.rb', line 4230

def child_nodes
  [keyword, statements]
end

#deconstruct_keys(keys) ⇒ Object



4236
4237
4238
4239
4240
4241
4242
4243
# File 'lib/syntax_tree/node.rb', line 4236

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

#format(q) ⇒ Object



4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
# File 'lib/syntax_tree/node.rb', line 4245

def format(q)
  q.format(keyword)

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