Class: SyntaxTree::Command

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

Overview

Command represents a method call with arguments and no parentheses. Note that Command nodes only happen when there is no explicit receiver for this method.

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(message:, arguments:, location:, comments: []) ⇒ Command

Returns a new instance of Command.



2861
2862
2863
2864
2865
2866
# File 'lib/syntax_tree/node.rb', line 2861

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

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments being sent with the message



2856
2857
2858
# File 'lib/syntax_tree/node.rb', line 2856

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2859
2860
2861
# File 'lib/syntax_tree/node.rb', line 2859

def comments
  @comments
end

#messageObject (readonly)

Const | Ident

the message being sent to the implicit receiver



2853
2854
2855
# File 'lib/syntax_tree/node.rb', line 2853

def message
  @message
end

Instance Method Details

#accept(visitor) ⇒ Object



2868
2869
2870
# File 'lib/syntax_tree/node.rb', line 2868

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

#child_nodesObject Also known as: deconstruct



2872
2873
2874
# File 'lib/syntax_tree/node.rb', line 2872

def child_nodes
  [message, arguments]
end

#deconstruct_keys(keys) ⇒ Object



2878
2879
2880
2881
2882
2883
2884
2885
# File 'lib/syntax_tree/node.rb', line 2878

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

#format(q) ⇒ Object



2887
2888
2889
2890
2891
2892
# File 'lib/syntax_tree/node.rb', line 2887

def format(q)
  q.group do
    q.format(message)
    align(q, self) { q.format(arguments) }
  end
end