Class: Prism::DefinedNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::DefinedNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Class Method Summary collapse
-
.type ⇒ :defined_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, lparen_loc: self.lparen_loc, value: self.value, rparen_loc: self.rparen_loc, keyword_loc: self.keyword_loc) ⇒ DefinedNode
:call-seq: copy(**fields) -> DefinedNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, lparen_loc, value, rparen_loc, keyword_loc) ⇒ DefinedNode
constructor
Initialize a new DefinedNode node.
-
#inspect ⇒ String
: () -> String.
-
#keyword ⇒ String
:call-seq: keyword -> String.
-
#keyword_loc ⇒ Location
:category: Locations :call-seq: keyword_loc -> Location.
-
#lparen ⇒ String?
:call-seq: lparen -> String | nil.
-
#lparen_loc ⇒ Location?
:category: Locations :call-seq: lparen_loc -> Location | nil.
-
#rparen ⇒ String?
:call-seq: rparen -> String | nil.
-
#rparen_loc ⇒ Location?
:category: Locations :call-seq: rparen_loc -> Location | nil.
-
#save_keyword_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_lparen_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the lparen_loc location using the given saved source so that it can be retrieved later.
-
#save_rparen_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the rparen_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :defined_node
See
Node#type. -
#value ⇒ Prism::node
:call-seq: value -> Node.
Constructor Details
#initialize(source, node_id, location, flags, lparen_loc, value, rparen_loc, keyword_loc) ⇒ DefinedNode
Initialize a new DefinedNode node.
: (Source source, Integer node_id, Location location, Integer flags, Location? lparen_loc, Prism::node value, Location? rparen_loc, Location keyword_loc) -> void
11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 |
# File 'lib/prism/node.rb', line 11214 def initialize(source, node_id, location, flags, lparen_loc, value, rparen_loc, keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @lparen_loc = lparen_loc @value = value @rparen_loc = rparen_loc @keyword_loc = keyword_loc end |
Class Method Details
.type ⇒ :defined_node
See Node.type.
: () -> :defined_node
11308 11309 11310 |
# File 'lib/prism/node.rb', line 11308 def self.type :defined_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
11440 11441 11442 11443 11444 11445 11446 |
# File 'lib/prism/node.rb', line 11440 def ===(other) # :nodoc: other.is_a?(DefinedNode) && (lparen_loc.nil? == other.lparen_loc.nil?) && (value === other.value) && (rparen_loc.nil? == other.rparen_loc.nil?) && (keyword_loc.nil? == other.keyword_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
11239 11240 11241 |
# File 'lib/prism/node.rb', line 11239 def accept(visitor) visitor.visit_defined_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
11246 11247 11248 |
# File 'lib/prism/node.rb', line 11246 def child_nodes [value] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
11263 11264 11265 |
# File 'lib/prism/node.rb', line 11263 def compact_child_nodes [value] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, lparen_loc: self.lparen_loc, value: self.value, rparen_loc: self.rparen_loc, keyword_loc: self.keyword_loc) ⇒ DefinedNode
:call-seq:
copy(**fields) -> DefinedNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?lparen_loc: Location?, ?value: Prism::node, ?rparen_loc: Location?, ?keyword_loc: Location) -> DefinedNode
11273 11274 11275 |
# File 'lib/prism/node.rb', line 11273 def copy(node_id: self.node_id, location: self.location, flags: self.flags, lparen_loc: self.lparen_loc, value: self.value, rparen_loc: self.rparen_loc, keyword_loc: self.keyword_loc) DefinedNode.new(source, node_id, location, flags, lparen_loc, value, rparen_loc, keyword_loc) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
11280 11281 11282 11283 11284 11285 11286 11287 11288 11289 11290 11291 11292 11293 11294 11295 11296 |
# File 'lib/prism/node.rb', line 11280 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location lparen_loc value rparen_loc keyword_loc lparen rparen keyword]).each_with_object( {} #: Hash[Symbol, untyped] ) do |key, deconstructed| case key when :node_id then deconstructed[:node_id] = self.node_id when :location then deconstructed[:location] = self.location when :lparen_loc then deconstructed[:lparen_loc] = self.lparen_loc when :value then deconstructed[:value] = self.value when :rparen_loc then deconstructed[:rparen_loc] = self.rparen_loc when :keyword_loc then deconstructed[:keyword_loc] = self.keyword_loc when :lparen then deconstructed[:lparen] = self.lparen when :rparen then deconstructed[:rparen] = self.rparen when :keyword then deconstructed[:keyword] = self.keyword end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
11254 11255 11256 11257 11258 |
# File 'lib/prism/node.rb', line 11254 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield value end |
#inspect ⇒ String
: () -> String
11313 11314 11315 |
# File 'lib/prism/node.rb', line 11313 def inspect # :nodoc: InspectVisitor.compose(self) end |
#keyword ⇒ String
:call-seq:
keyword -> String
Slice the location of keyword_loc from the source.
: () -> String
11433 11434 11435 |
# File 'lib/prism/node.rb', line 11433 def keyword keyword_loc.slice end |
#keyword_loc ⇒ Location
:category: Locations :call-seq:
keyword_loc -> Location
Returns the Location represented by keyword_loc.
: () -> Location
11390 11391 11392 11393 11394 |
# File 'lib/prism/node.rb', line 11390 def keyword_loc location = @keyword_loc return location if location.is_a?(Location) @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#lparen ⇒ String?
:call-seq:
lparen -> String | nil
Slice the location of lparen_loc from the source.
: () -> String?
11413 11414 11415 |
# File 'lib/prism/node.rb', line 11413 def lparen lparen_loc&.slice end |
#lparen_loc ⇒ Location?
:category: Locations :call-seq:
lparen_loc -> Location | nil
Returns the Location represented by lparen_loc.
: () -> Location?
11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 |
# File 'lib/prism/node.rb', line 11326 def lparen_loc location = @lparen_loc case location when nil nil when Location location else @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#rparen ⇒ String?
:call-seq:
rparen -> String | nil
Slice the location of rparen_loc from the source.
: () -> String?
11423 11424 11425 |
# File 'lib/prism/node.rb', line 11423 def rparen rparen_loc&.slice end |
#rparen_loc ⇒ Location?
:category: Locations :call-seq:
rparen_loc -> Location | nil
Returns the Location represented by rparen_loc.
: () -> Location?
11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 |
# File 'lib/prism/node.rb', line 11363 def rparen_loc location = @rparen_loc case location when nil nil when Location location else @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#save_keyword_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the keyword_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
11401 11402 11403 |
# File 'lib/prism/node.rb', line 11401 def save_keyword_loc(repository) repository.enter(node_id, :keyword_loc) end |
#save_lparen_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the lparen_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry?
11343 11344 11345 |
# File 'lib/prism/node.rb', line 11343 def save_lparen_loc(repository) repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil? end |
#save_rparen_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the rparen_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry?
11380 11381 11382 |
# File 'lib/prism/node.rb', line 11380 def save_rparen_loc(repository) repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil? end |
#type ⇒ :defined_node
See Node#type.
: () -> :defined_node
11301 11302 11303 |
# File 'lib/prism/node.rb', line 11301 def type :defined_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
Returns the value attribute.
: () -> Prism::node
11352 11353 11354 |
# File 'lib/prism/node.rb', line 11352 def value @value end |