Class: SyntaxTree::CommandCall

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

CommandCall represents a method call on an object with arguments and no parentheses.

object.method argument

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ CommandCall

Returns a new instance of CommandCall.



3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
# File 'lib/syntax_tree.rb', line 3888

def initialize(
  receiver:,
  operator:,
  message:,
  arguments:,
  location:,
  comments: []
)
  @receiver = receiver
  @operator = operator
  @message = message
  @arguments = arguments
  @location = location
  @comments = comments
end

Instance Attribute Details

#argumentsObject (readonly)

nil | Args

the arguments going along with the message



3880
3881
3882
# File 'lib/syntax_tree.rb', line 3880

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3886
3887
3888
# File 'lib/syntax_tree.rb', line 3886

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



3883
3884
3885
# File 'lib/syntax_tree.rb', line 3883

def location
  @location
end

#messageObject (readonly)

Const | Ident | Op

the message being send



3877
3878
3879
# File 'lib/syntax_tree.rb', line 3877

def message
  @message
end

#operatorObject (readonly)

:“::” | Op | Period

the operator used to send the message



3874
3875
3876
# File 'lib/syntax_tree.rb', line 3874

def operator
  @operator
end

#receiverObject (readonly)

untyped

the receiver of the message



3871
3872
3873
# File 'lib/syntax_tree.rb', line 3871

def receiver
  @receiver
end

Instance Method Details

#child_nodesObject



3904
3905
3906
# File 'lib/syntax_tree.rb', line 3904

def child_nodes
  [receiver, message, arguments]
end

#format(q) ⇒ Object



3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
# File 'lib/syntax_tree.rb', line 3908

def format(q)
  q.group do
    doc =
      q.nest(0) do
        q.format(receiver)
        q.format(CallOperatorFormatter.new(operator), stackable: false)
        q.format(message)
      end

    if arguments
      q.text(" ")
      q.nest(argument_alignment(q, doc)) { q.format(arguments) }
    end
  end
end

#pretty_print(q) ⇒ Object



3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
# File 'lib/syntax_tree.rb', line 3924

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("command_call")

    q.breakable
    q.pp(receiver)

    q.breakable
    q.pp(operator)

    q.breakable
    q.pp(message)

    if arguments
      q.breakable
      q.pp(arguments)
    end

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
# File 'lib/syntax_tree.rb', line 3946

def to_json(*opts)
  {
    type: :command_call,
    receiver: receiver,
    op: operator,
    message: message,
    args: arguments,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end