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.



3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
# File 'lib/syntax_tree.rb', line 3767

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



3759
3760
3761
# File 'lib/syntax_tree.rb', line 3759

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3765
3766
3767
# File 'lib/syntax_tree.rb', line 3765

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



3762
3763
3764
# File 'lib/syntax_tree.rb', line 3762

def location
  @location
end

#messageObject (readonly)

Const | Ident | Op

the message being send



3756
3757
3758
# File 'lib/syntax_tree.rb', line 3756

def message
  @message
end

#operatorObject (readonly)

:“::” | Op | Period

the operator used to send the message



3753
3754
3755
# File 'lib/syntax_tree.rb', line 3753

def operator
  @operator
end

#receiverObject (readonly)

untyped

the receiver of the message



3750
3751
3752
# File 'lib/syntax_tree.rb', line 3750

def receiver
  @receiver
end

Instance Method Details

#child_nodesObject



3783
3784
3785
# File 'lib/syntax_tree.rb', line 3783

def child_nodes
  [receiver, message, arguments]
end

#format(q) ⇒ Object



3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
# File 'lib/syntax_tree.rb', line 3787

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



3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
# File 'lib/syntax_tree.rb', line 3803

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



3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
# File 'lib/syntax_tree.rb', line 3825

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