Class: Prism::EmbeddedStatementsNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents an interpolated set of statements.

"foo #{bar}"
     ^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, opening_loc, statements, closing_loc) ⇒ EmbeddedStatementsNode

Initialize a new EmbeddedStatementsNode node.



6847
6848
6849
6850
6851
6852
6853
6854
6855
# File 'lib/prism/node.rb', line 6847

def initialize(source, node_id, location, flags, opening_loc, statements, closing_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @opening_loc = opening_loc
  @statements = statements
  @closing_loc = closing_loc
end

Instance Attribute Details

#statementsObject (readonly)

attr_reader statements: StatementsNode?



6913
6914
6915
# File 'lib/prism/node.rb', line 6913

def statements
  @statements
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See Node::type.



6949
6950
6951
# File 'lib/prism/node.rb', line 6949

def self.type
  :embedded_statements_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



6955
6956
6957
6958
6959
6960
# File 'lib/prism/node.rb', line 6955

def ===(other)
  other.is_a?(EmbeddedStatementsNode) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (statements === other.statements) &&
    (closing_loc.nil? == other.closing_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



6858
6859
6860
# File 'lib/prism/node.rb', line 6858

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



6863
6864
6865
# File 'lib/prism/node.rb', line 6863

def child_nodes
  [statements]
end

#closingObject

def closing: () -> String



6934
6935
6936
# File 'lib/prism/node.rb', line 6934

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



6916
6917
6918
6919
6920
# File 'lib/prism/node.rb', line 6916

def closing_loc
  location = @closing_loc
  return location if location.is_a?(Location)
  @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



6882
6883
6884
# File 'lib/prism/node.rb', line 6882

def comment_targets
  [opening_loc, *statements, closing_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



6875
6876
6877
6878
6879
# File 'lib/prism/node.rb', line 6875

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << statements if statements
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, statements: self.statements, closing_loc: self.closing_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?statements: StatementsNode?, ?closing_loc: Location) -> EmbeddedStatementsNode



6887
6888
6889
# File 'lib/prism/node.rb', line 6887

def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, statements: self.statements, closing_loc: self.closing_loc)
  EmbeddedStatementsNode.new(source, node_id, location, flags, opening_loc, statements, closing_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location, statements: StatementsNode?, closing_loc: Location }



6895
6896
6897
# File 'lib/prism/node.rb', line 6895

def deconstruct_keys(keys)
  { node_id: node_id, location: location, opening_loc: opening_loc, statements: statements, closing_loc: closing_loc }
end

#each_child_node {|statements| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



6868
6869
6870
6871
6872
# File 'lib/prism/node.rb', line 6868

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield statements if statements
end

#inspectObject

def inspect -> String



6939
6940
6941
# File 'lib/prism/node.rb', line 6939

def inspect
  InspectVisitor.compose(self)
end

#openingObject

def opening: () -> String



6929
6930
6931
# File 'lib/prism/node.rb', line 6929

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



6900
6901
6902
6903
6904
# File 'lib/prism/node.rb', line 6900

def opening_loc
  location = @opening_loc
  return location if location.is_a?(Location)
  @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#save_closing_loc(repository) ⇒ Object

Save the closing_loc location using the given saved source so that it can be retrieved later.



6924
6925
6926
# File 'lib/prism/node.rb', line 6924

def save_closing_loc(repository)
  repository.enter(node_id, :closing_loc)
end

#save_opening_loc(repository) ⇒ Object

Save the opening_loc location using the given saved source so that it can be retrieved later.



6908
6909
6910
# File 'lib/prism/node.rb', line 6908

def save_opening_loc(repository)
  repository.enter(node_id, :opening_loc)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



6944
6945
6946
# File 'lib/prism/node.rb', line 6944

def type
  :embedded_statements_node
end