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.



3865
3866
3867
3868
3869
3870
# File 'lib/syntax_tree/node.rb', line 3865

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



3863
3864
3865
# File 'lib/syntax_tree/node.rb', line 3863

def comments
  @comments
end

#keywordObject (readonly)

Kw

the ensure keyword that began this node



3857
3858
3859
# File 'lib/syntax_tree/node.rb', line 3857

def keyword
  @keyword
end

#statementsObject (readonly)

Statements

the expressions to be executed



3860
3861
3862
# File 'lib/syntax_tree/node.rb', line 3860

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



3872
3873
3874
# File 'lib/syntax_tree/node.rb', line 3872

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

#child_nodesObject Also known as: deconstruct



3876
3877
3878
# File 'lib/syntax_tree/node.rb', line 3876

def child_nodes
  [keyword, statements]
end

#deconstruct_keys(keys) ⇒ Object



3882
3883
3884
3885
3886
3887
3888
3889
# File 'lib/syntax_tree/node.rb', line 3882

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

#format(q) ⇒ Object



3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
# File 'lib/syntax_tree/node.rb', line 3891

def format(q)
  q.format(keyword)

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