Class: Prism::EmbeddedStatementsNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::EmbeddedStatementsNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents an interpolated set of statements.
"foo #{bar}"
^^^^^^
Instance Attribute Summary collapse
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location.
-
#statements ⇒ Object
readonly
attr_reader statements: StatementsNode?.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(**params) ⇒ Object
def copy: (**params) -> EmbeddedStatementsNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(opening_loc, statements, closing_loc, location) ⇒ EmbeddedStatementsNode
constructor
def initialize: (opening_loc: Location, statements: StatementsNode?, closing_loc: Location, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#opening ⇒ Object
def opening: () -> String.
-
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform.
Constructor Details
#initialize(opening_loc, statements, closing_loc, location) ⇒ EmbeddedStatementsNode
def initialize: (opening_loc: Location, statements: StatementsNode?, closing_loc: Location, location: Location) -> void
4943 4944 4945 4946 4947 4948 |
# File 'lib/prism/node.rb', line 4943 def initialize(opening_loc, statements, closing_loc, location) @opening_loc = opening_loc @statements = statements @closing_loc = closing_loc @location = location end |
Instance Attribute Details
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location
4940 4941 4942 |
# File 'lib/prism/node.rb', line 4940 def closing_loc @closing_loc end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location
4934 4935 4936 |
# File 'lib/prism/node.rb', line 4934 def opening_loc @opening_loc end |
#statements ⇒ Object (readonly)
attr_reader statements: StatementsNode?
4937 4938 4939 |
# File 'lib/prism/node.rb', line 4937 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
4951 4952 4953 |
# File 'lib/prism/node.rb', line 4951 def accept(visitor) visitor.(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
4956 4957 4958 |
# File 'lib/prism/node.rb', line 4956 def child_nodes [statements] end |
#closing ⇒ Object
def closing: () -> String
4996 4997 4998 |
# File 'lib/prism/node.rb', line 4996 def closing closing_loc.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
4968 4969 4970 |
# File 'lib/prism/node.rb', line 4968 def comment_targets [opening_loc, *statements, closing_loc] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
4961 4962 4963 4964 4965 |
# File 'lib/prism/node.rb', line 4961 def compact_child_nodes compact = [] compact << statements if statements compact end |
#copy(**params) ⇒ Object
def copy: (**params) -> EmbeddedStatementsNode
4973 4974 4975 4976 4977 4978 4979 4980 |
# File 'lib/prism/node.rb', line 4973 def copy(**params) EmbeddedStatementsNode.new( params.fetch(:opening_loc) { opening_loc }, params.fetch(:statements) { statements }, params.fetch(:closing_loc) { closing_loc }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
4986 4987 4988 |
# File 'lib/prism/node.rb', line 4986 def deconstruct_keys(keys) { opening_loc: opening_loc, statements: statements, closing_loc: closing_loc, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 |
# File 'lib/prism/node.rb', line 5000 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n" if (statements = self.statements).nil? inspector << "├── statements: ∅\n" else inspector << "├── statements:\n" inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n" inspector.to_str end |
#opening ⇒ Object
def opening: () -> String
4991 4992 4993 |
# File 'lib/prism/node.rb', line 4991 def opening opening_loc.slice end |
#type ⇒ Object
Sometimes you want to check an instance of a node against a list of classes to see what kind of behavior to perform. Usually this is done by calling ‘[cls1, cls2].include?(node.class)` or putting the node into a case statement and doing `case node; when cls1; when cls2; end`. Both of these approaches are relatively slow because of the constant lookups, method calls, and/or array allocations.
Instead, you can call #type, which will return to you a symbol that you can use for comparison. This is faster than the other approaches because it uses a single integer comparison, but also because if you’re on CRuby you can take advantage of the fact that case statements with all symbol keys will use a jump table.
def type: () -> Symbol
5027 5028 5029 |
# File 'lib/prism/node.rb', line 5027 def type :embedded_statements_node end |