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

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(message:, arguments:, location:, comments: []) ⇒ Command

Returns a new instance of Command.



2950
2951
2952
2953
2954
2955
# File 'lib/syntax_tree/node.rb', line 2950

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



2945
2946
2947
# File 'lib/syntax_tree/node.rb', line 2945

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2948
2949
2950
# File 'lib/syntax_tree/node.rb', line 2948

def comments
  @comments
end

#messageObject (readonly)

Const | Ident

the message being sent to the implicit receiver



2942
2943
2944
# File 'lib/syntax_tree/node.rb', line 2942

def message
  @message
end

Instance Method Details

#accept(visitor) ⇒ Object



2957
2958
2959
# File 'lib/syntax_tree/node.rb', line 2957

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

#child_nodesObject Also known as: deconstruct



2961
2962
2963
# File 'lib/syntax_tree/node.rb', line 2961

def child_nodes
  [message, arguments]
end

#deconstruct_keys(_keys) ⇒ Object



2967
2968
2969
2970
2971
2972
2973
2974
# File 'lib/syntax_tree/node.rb', line 2967

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

#format(q) ⇒ Object



2976
2977
2978
2979
2980
2981
# File 'lib/syntax_tree/node.rb', line 2976

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