Class: Prism::LambdaNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::LambdaNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents using a lambda literal (not the lambda method call).
->(value) { value * 2 }
^^^^^^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: StatementsNode | BeginNode | nil.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#parameters ⇒ Object
readonly
attr_reader parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#closing ⇒ Object
def closing: () -> String.
-
#closing_loc ⇒ Object
attr_reader closing_loc: Location.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, operator_loc: self.operator_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc, parameters: self.parameters, body: self.body) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?operator_loc: Location, ?opening_loc: Location, ?closing_loc: Location, ?parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil, ?body: StatementsNode | BeginNode | nil) -> LambdaNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body) ⇒ LambdaNode
constructor
Initialize a new LambdaNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#opening ⇒ Object
def opening: () -> String.
-
#opening_loc ⇒ Object
attr_reader opening_loc: Location.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location.
-
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Object
Save the opening_loc location using the given saved source so that it can be retrieved later.
-
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body) ⇒ LambdaNode
Initialize a new LambdaNode node.
11638 11639 11640 11641 11642 11643 11644 11645 11646 11647 11648 11649 |
# File 'lib/prism/node.rb', line 11638 def initialize(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body) @source = source @node_id = node_id @location = location @flags = flags @locals = locals @operator_loc = operator_loc @opening_loc = opening_loc @closing_loc = closing_loc @parameters = parameters @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: StatementsNode | BeginNode | nil
11733 11734 11735 |
# File 'lib/prism/node.rb', line 11733 def body @body end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
11688 11689 11690 |
# File 'lib/prism/node.rb', line 11688 def locals @locals end |
#parameters ⇒ Object (readonly)
attr_reader parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil
11730 11731 11732 |
# File 'lib/prism/node.rb', line 11730 def parameters @parameters end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
11761 11762 11763 |
# File 'lib/prism/node.rb', line 11761 def self.type :lambda_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.
11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 |
# File 'lib/prism/node.rb', line 11767 def ===(other) other.is_a?(LambdaNode) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (operator_loc.nil? == other.operator_loc.nil?) && (opening_loc.nil? == other.opening_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) && (parameters === other.parameters) && (body === other.body) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
11652 11653 11654 |
# File 'lib/prism/node.rb', line 11652 def accept(visitor) visitor.visit_lambda_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
11657 11658 11659 |
# File 'lib/prism/node.rb', line 11657 def child_nodes [parameters, body] end |
#closing ⇒ Object
def closing: () -> String
11746 11747 11748 |
# File 'lib/prism/node.rb', line 11746 def closing closing_loc.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location
11717 11718 11719 11720 11721 |
# File 'lib/prism/node.rb', line 11717 def closing_loc location = @closing_loc return location if location.is_a?(Location) @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
11670 11671 11672 |
# File 'lib/prism/node.rb', line 11670 def comment_targets [operator_loc, opening_loc, closing_loc, *parameters, *body] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
11662 11663 11664 11665 11666 11667 |
# File 'lib/prism/node.rb', line 11662 def compact_child_nodes compact = [] #: Array[Prism::node] compact << parameters if parameters compact << body if body compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, operator_loc: self.operator_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc, parameters: self.parameters, body: self.body) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?operator_loc: Location, ?opening_loc: Location, ?closing_loc: Location, ?parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil, ?body: StatementsNode | BeginNode | nil) -> LambdaNode
11675 11676 11677 |
# File 'lib/prism/node.rb', line 11675 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, operator_loc: self.operator_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc, parameters: self.parameters, body: self.body) LambdaNode.new(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body) end |
#deconstruct_keys(keys) ⇒ Object
11683 11684 11685 |
# File 'lib/prism/node.rb', line 11683 def deconstruct_keys(keys) { node_id: node_id, location: location, locals: locals, operator_loc: operator_loc, opening_loc: opening_loc, closing_loc: closing_loc, parameters: parameters, body: body } end |
#inspect ⇒ Object
def inspect -> String
11751 11752 11753 |
# File 'lib/prism/node.rb', line 11751 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String
11741 11742 11743 |
# File 'lib/prism/node.rb', line 11741 def opening opening_loc.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location
11704 11705 11706 11707 11708 |
# File 'lib/prism/node.rb', line 11704 def opening_loc location = @opening_loc return location if location.is_a?(Location) @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ Object
def operator: () -> String
11736 11737 11738 |
# File 'lib/prism/node.rb', line 11736 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
11691 11692 11693 11694 11695 |
# File 'lib/prism/node.rb', line 11691 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_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.
11725 11726 11727 |
# File 'lib/prism/node.rb', line 11725 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.
11712 11713 11714 |
# File 'lib/prism/node.rb', line 11712 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) end |
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
11699 11700 11701 |
# File 'lib/prism/node.rb', line 11699 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
11756 11757 11758 |
# File 'lib/prism/node.rb', line 11756 def type :lambda_node end |