Class: SyntaxTree::CommandCall

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

Overview

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

object.method argument

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of CommandCall.



2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
# File 'lib/syntax_tree/node.rb', line 2591

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



2586
2587
2588
# File 'lib/syntax_tree/node.rb', line 2586

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2589
2590
2591
# File 'lib/syntax_tree/node.rb', line 2589

def comments
  @comments
end

#messageObject (readonly)

Const | Ident | Op

the message being send



2583
2584
2585
# File 'lib/syntax_tree/node.rb', line 2583

def message
  @message
end

#operatorObject (readonly)

:“::” | Op | Period

the operator used to send the message



2580
2581
2582
# File 'lib/syntax_tree/node.rb', line 2580

def operator
  @operator
end

#receiverObject (readonly)

untyped

the receiver of the message



2577
2578
2579
# File 'lib/syntax_tree/node.rb', line 2577

def receiver
  @receiver
end

Instance Method Details

#accept(visitor) ⇒ Object



2607
2608
2609
# File 'lib/syntax_tree/node.rb', line 2607

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

#child_nodesObject Also known as: deconstruct



2611
2612
2613
# File 'lib/syntax_tree/node.rb', line 2611

def child_nodes
  [receiver, message, arguments]
end

#deconstruct_keys(keys) ⇒ Object



2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
# File 'lib/syntax_tree/node.rb', line 2617

def deconstruct_keys(keys)
  {
    receiver: receiver,
    operator: operator,
    message: message,
    arguments: arguments,
    location: location,
    comments: comments
  }
end

#format(q) ⇒ Object



2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
# File 'lib/syntax_tree/node.rb', line 2628

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