Class: Prism::BlockParametersNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::BlockParametersNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Represents a block's parameters declaration.
-> (a, b = 1; local) { }
^^^^^^^^^^^^^^^^^
foo do |a, b = 1; local|
^^^^^^^^^^^^^^^^^
end
Class Method Summary collapse
-
.type ⇒ :block_parameters_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.
-
#closing ⇒ String?
:call-seq: closing -> String | nil.
-
#closing_loc ⇒ Location?
:category: Locations :call-seq: closing_loc -> Location | nil.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, parameters: self.parameters, locals: self.locals, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ BlockParametersNode
:call-seq: copy(**fields) -> BlockParametersNode.
-
#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, parameters, locals, opening_loc, closing_loc) ⇒ BlockParametersNode
constructor
Initialize a new BlockParametersNode node.
-
#inspect ⇒ String
: () -> String.
-
#locals ⇒ Array[BlockLocalVariableNode]
:call-seq: locals -> Array.
-
#opening ⇒ String?
:call-seq: opening -> String | nil.
-
#opening_loc ⇒ Location?
:category: Locations :call-seq: opening_loc -> Location | nil.
-
#parameters ⇒ ParametersNode?
:call-seq: parameters -> ParametersNode | nil.
-
#save_closing_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :block_parameters_node
See
Node#type.
Constructor Details
#initialize(source, node_id, location, flags, parameters, locals, opening_loc, closing_loc) ⇒ BlockParametersNode
Initialize a new BlockParametersNode node.
: (Source source, Integer node_id, Location location, Integer flags, ParametersNode? parameters, Array locals, Location? opening_loc, Location? closing_loc) -> void
3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 |
# File 'lib/prism/node.rb', line 3709 def initialize(source, node_id, location, flags, parameters, locals, opening_loc, closing_loc) @source = source @node_id = node_id @location = location @flags = flags @parameters = parameters @locals = locals @opening_loc = opening_loc @closing_loc = closing_loc end |
Class Method Details
.type ⇒ :block_parameters_node
See Node.type.
: () -> :block_parameters_node
3806 3807 3808 |
# File 'lib/prism/node.rb', line 3806 def self.type :block_parameters_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
3960 3961 3962 3963 3964 3965 3966 3967 |
# File 'lib/prism/node.rb', line 3960 def ===(other) # :nodoc: other.is_a?(BlockParametersNode) && (parameters === other.parameters) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (opening_loc.nil? == other.opening_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
3734 3735 3736 |
# File 'lib/prism/node.rb', line 3734 def accept(visitor) visitor.visit_block_parameters_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
3741 3742 3743 |
# File 'lib/prism/node.rb', line 3741 def child_nodes [parameters, *locals] end |
#closing ⇒ String?
:call-seq:
closing -> String | nil
Slice the location of closing_loc from the source.
: () -> String?
3953 3954 3955 |
# File 'lib/prism/node.rb', line 3953 def closing closing_loc&.slice end |
#closing_loc ⇒ Location?
:category: Locations :call-seq:
closing_loc -> Location | nil
Represents the closing Location of the block parameters.
-> (a, b = 1; local) { }
^
foo do |a, b = 1; local|
^
end
: () -> Location?
3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 |
# File 'lib/prism/node.rb', line 3915 def closing_loc location = @closing_loc case location when nil nil when Location location else @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
3759 3760 3761 3762 3763 3764 |
# File 'lib/prism/node.rb', line 3759 def compact_child_nodes compact = [] #: Array[Prism::node] if (parameters = self.parameters); compact << parameters; end compact.concat(locals) compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, parameters: self.parameters, locals: self.locals, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ BlockParametersNode
:call-seq:
copy(**fields) -> BlockParametersNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?parameters: ParametersNode?, ?locals: Array, ?opening_loc: Location?, ?closing_loc: Location?) -> BlockParametersNode
3772 3773 3774 |
# File 'lib/prism/node.rb', line 3772 def copy(node_id: self.node_id, location: self.location, flags: self.flags, parameters: self.parameters, locals: self.locals, opening_loc: self.opening_loc, closing_loc: self.closing_loc) BlockParametersNode.new(source, node_id, location, flags, parameters, locals, opening_loc, closing_loc) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 |
# File 'lib/prism/node.rb', line 3779 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location parameters locals opening_loc closing_loc opening closing]).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 :parameters then deconstructed[:parameters] = self.parameters when :locals then deconstructed[:locals] = self.locals when :opening_loc then deconstructed[:opening_loc] = self.opening_loc when :closing_loc then deconstructed[:closing_loc] = self.closing_loc when :opening then deconstructed[:opening] = self.opening when :closing then deconstructed[:closing] = self.closing end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
3749 3750 3751 3752 3753 3754 |
# File 'lib/prism/node.rb', line 3749 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? if (parameters = self.parameters); yield parameters; end locals.each { |node| yield node } end |
#inspect ⇒ String
: () -> String
3811 3812 3813 |
# File 'lib/prism/node.rb', line 3811 def inspect # :nodoc: InspectVisitor.compose(self) end |
#locals ⇒ Array[BlockLocalVariableNode]
:call-seq:
locals -> Array[BlockLocalVariableNode]
Represents the local variables of the block.
-> (a, b = 1; local) { }
^^^^^
foo do |a, b = 1; local|
^^^^^
end
: () -> Array
3855 3856 3857 |
# File 'lib/prism/node.rb', line 3855 def locals @locals end |
#opening ⇒ String?
:call-seq:
opening -> String | nil
Slice the location of opening_loc from the source.
: () -> String?
3943 3944 3945 |
# File 'lib/prism/node.rb', line 3943 def opening opening_loc&.slice end |
#opening_loc ⇒ Location?
:category: Locations :call-seq:
opening_loc -> Location | nil
Represents the opening Location of the block parameters.
-> (a, b = 1; local) { }
^
foo do |a, b = 1; local|
^
end
: () -> Location?
3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 |
# File 'lib/prism/node.rb', line 3877 def opening_loc location = @opening_loc case location when nil nil when Location location else @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#parameters ⇒ ParametersNode?
:call-seq:
parameters -> ParametersNode | nil
Represents the parameters of the block.
-> (a, b = 1; local) { }
^^^^^^^^
foo do |a, b = 1; local|
^^^^^^^^
end
: () -> ParametersNode?
3834 3835 3836 |
# File 'lib/prism/node.rb', line 3834 def parameters @parameters end |
#save_closing_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry?
3932 3933 3934 |
# File 'lib/prism/node.rb', line 3932 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) unless @closing_loc.nil? end |
#save_opening_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry?
3894 3895 3896 |
# File 'lib/prism/node.rb', line 3894 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) unless @opening_loc.nil? end |
#type ⇒ :block_parameters_node
See Node#type.
: () -> :block_parameters_node
3799 3800 3801 |
# File 'lib/prism/node.rb', line 3799 def type :block_parameters_node end |