Class: YARP::BlockNode

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

Overview

Represents a block of ruby code.

[1, 2, 3].each { |i| puts x }

^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locals, parameters, body, opening_loc, closing_loc, location) ⇒ BlockNode

def initialize: (locals: Array, parameters: BlockParametersNode?, body: Node?, opening_loc: Location, closing_loc: Location, location: Location) -> void



665
666
667
668
669
670
671
672
# File 'lib/yarp/node.rb', line 665

def initialize(locals, parameters, body, opening_loc, closing_loc, location)
  @locals = locals
  @parameters = parameters
  @body = body
  @opening_loc = opening_loc
  @closing_loc = closing_loc
  @location = location
end

Instance Attribute Details

#bodyObject (readonly)

attr_reader body: Node?



656
657
658
# File 'lib/yarp/node.rb', line 656

def body
  @body
end

#closing_locObject (readonly)

attr_reader closing_loc: Location



662
663
664
# File 'lib/yarp/node.rb', line 662

def closing_loc
  @closing_loc
end

#localsObject (readonly)

attr_reader locals: Array



650
651
652
# File 'lib/yarp/node.rb', line 650

def locals
  @locals
end

#opening_locObject (readonly)

attr_reader opening_loc: Location



659
660
661
# File 'lib/yarp/node.rb', line 659

def opening_loc
  @opening_loc
end

#parametersObject (readonly)

attr_reader parameters: BlockParametersNode?



653
654
655
# File 'lib/yarp/node.rb', line 653

def parameters
  @parameters
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



675
676
677
# File 'lib/yarp/node.rb', line 675

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

#child_nodesObject Also known as: deconstruct

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



680
681
682
# File 'lib/yarp/node.rb', line 680

def child_nodes
  [parameters, body]
end

#closingObject

def closing: () -> String



710
711
712
# File 'lib/yarp/node.rb', line 710

def closing
  closing_loc.slice
end

#copy(**params) ⇒ Object

def copy: (**params) -> BlockNode



685
686
687
688
689
690
691
692
693
694
# File 'lib/yarp/node.rb', line 685

def copy(**params)
  BlockNode.new(
    params.fetch(:locals) { locals },
    params.fetch(:parameters) { parameters },
    params.fetch(:body) { body },
    params.fetch(:opening_loc) { opening_loc },
    params.fetch(:closing_loc) { closing_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



700
701
702
# File 'lib/yarp/node.rb', line 700

def deconstruct_keys(keys)
  { locals: locals, parameters: parameters, body: body, opening_loc: opening_loc, closing_loc: closing_loc, location: location }
end

#openingObject

def opening: () -> String



705
706
707
# File 'lib/yarp/node.rb', line 705

def opening
  opening_loc.slice
end