Class: YARP::CallNode

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

Overview

Represents a method call, in all of the various forms that can take.

foo
^^^

foo()
^^^^^

+foo
^^^^

foo + bar
^^^^^^^^^

foo.bar
^^^^^^^

foo&.bar
^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver, operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location) ⇒ CallNode

def initialize: (receiver: Node?, operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: Node?, closing_loc: Location?, block: Node?, flags: Integer, name: String, location: Location) -> void



791
792
793
794
795
796
797
798
799
800
801
802
# File 'lib/yarp/node.rb', line 791

def initialize(receiver, operator_loc, message_loc, opening_loc, arguments, closing_loc, block, flags, name, location)
  @receiver = receiver
  @operator_loc = operator_loc
  @message_loc = message_loc
  @opening_loc = opening_loc
  @arguments = arguments
  @closing_loc = closing_loc
  @block = block
  @flags = flags
  @name = name
  @location = location
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: Node?



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

def arguments
  @arguments
end

#blockObject (readonly)

attr_reader block: Node?



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

def block
  @block
end

#closing_locObject (readonly)

attr_reader closing_loc: Location?



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

def closing_loc
  @closing_loc
end

#flagsObject (readonly)

attr_reader flags: Integer



785
786
787
# File 'lib/yarp/node.rb', line 785

def flags
  @flags
end

#message_locObject (readonly)

attr_reader message_loc: Location?



770
771
772
# File 'lib/yarp/node.rb', line 770

def message_loc
  @message_loc
end

#nameObject (readonly)

attr_reader name: String



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

def name
  @name
end

#opening_locObject (readonly)

attr_reader opening_loc: Location?



773
774
775
# File 'lib/yarp/node.rb', line 773

def opening_loc
  @opening_loc
end

#operator_locObject (readonly)

attr_reader operator_loc: Location?



767
768
769
# File 'lib/yarp/node.rb', line 767

def operator_loc
  @operator_loc
end

#receiverObject (readonly)

attr_reader receiver: Node?



764
765
766
# File 'lib/yarp/node.rb', line 764

def receiver
  @receiver
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



805
806
807
# File 'lib/yarp/node.rb', line 805

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

#child_nodesObject Also known as: deconstruct

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



810
811
812
# File 'lib/yarp/node.rb', line 810

def child_nodes
  [receiver, arguments, block]
end

#closingObject

def closing: () -> String?



838
839
840
# File 'lib/yarp/node.rb', line 838

def closing
  closing_loc&.slice
end

#deconstruct_keys(keys) ⇒ Object

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



818
819
820
# File 'lib/yarp/node.rb', line 818

def deconstruct_keys(keys)
  { receiver: receiver, operator_loc: operator_loc, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block, flags: flags, name: name, location: location }
end

#messageObject

def message: () -> String?



828
829
830
# File 'lib/yarp/node.rb', line 828

def message
  message_loc&.slice
end

#openingObject

def opening: () -> String?



833
834
835
# File 'lib/yarp/node.rb', line 833

def opening
  opening_loc&.slice
end

#operatorObject

def operator: () -> String?



823
824
825
# File 'lib/yarp/node.rb', line 823

def operator
  operator_loc&.slice
end

#safe_navigation?Boolean

def safe_navigation?: () -> bool

Returns:

  • (Boolean)


843
844
845
# File 'lib/yarp/node.rb', line 843

def safe_navigation?
  flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
end

#variable_call?Boolean

def variable_call?: () -> bool

Returns:

  • (Boolean)


848
849
850
# File 'lib/yarp/node.rb', line 848

def variable_call?
  flags.anybits?(CallNodeFlags::VARIABLE_CALL)
end