Class: YARP::BlockArgumentNode

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

Overview

Represents block method arguments.

bar(&args)
^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression, operator_loc, location) ⇒ BlockArgumentNode

def initialize: (expression: Node?, operator_loc: Location, location: Location) -> void



782
783
784
785
786
# File 'lib/yarp/node.rb', line 782

def initialize(expression, operator_loc, location)
  @expression = expression
  @operator_loc = operator_loc
  @location = location
end

Instance Attribute Details

#expressionObject (readonly)

attr_reader expression: Node?



776
777
778
# File 'lib/yarp/node.rb', line 776

def expression
  @expression
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



779
780
781
# File 'lib/yarp/node.rb', line 779

def operator_loc
  @operator_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



789
790
791
# File 'lib/yarp/node.rb', line 789

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



794
795
796
# File 'lib/yarp/node.rb', line 794

def child_nodes
  [expression]
end

#comment_targetsObject

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



799
800
801
# File 'lib/yarp/node.rb', line 799

def comment_targets
  [*expression, operator_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> BlockArgumentNode



804
805
806
807
808
809
810
# File 'lib/yarp/node.rb', line 804

def copy(**params)
  BlockArgumentNode.new(
    params.fetch(:expression) { expression },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



816
817
818
# File 'lib/yarp/node.rb', line 816

def deconstruct_keys(keys)
  { expression: expression, operator_loc: operator_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



825
826
827
828
829
830
831
832
833
834
835
# File 'lib/yarp/node.rb', line 825

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  if (expression = self.expression).nil?
    inspector << "├── expression: ∅\n"
  else
    inspector << "├── expression:\n"
    inspector << expression.inspect(inspector.child_inspector("")).delete_prefix(inspector.prefix)
  end
  inspector << "└── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector.to_str
end

#operatorObject

def operator: () -> String



821
822
823
# File 'lib/yarp/node.rb', line 821

def operator
  operator_loc.slice
end